#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int q;
  cin >> q;
  vector<int> b(q);
  vector<int> c(q);
  for (int i = 0; i < q; ++i) {
    cin >> b[i] >> c[i];
  }
  vector<int> flag(q);
  for (int i = 0; i < n; ++i) {
    flag[a[i] - 1]++;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += a[i];
  }
  int cnt;
  for (int i = 0; i < q; ++i) {
    cnt = flag[b[i] - 1];
    flag[c[i] - 1] += cnt;
    flag[b[i] - 1] = 0;
    ans = ans + (c[i] - b[i]) * cnt;
    cout << ans << endl;
  }
  return 0;
}
