#include <bits/stdc++.h>
using namespace std;
long long sum(int n);
void go() {
  int n;
  cin >> n;
  int s = 0;
  unordered_map<int, int> cnt;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    cnt[x]++;
    s += x;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    if (cnt.count(b)) {
      cnt[c] += cnt[b];
      s -= cnt[b] * b;
      s += cnt[b] * c;
    }
    cout << s << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  go();
  return 0;
}
long long sum(int n) {
  if (n == 0) {
    return n;
  } else {
    return sum(n / 10) + n % 10;
  }
}
