#include <bits/stdc++.h>
using namespace std;
int n, q, nr[100005], b, c;
long long sum;
map<int, int> m;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> nr[i];
    sum += nr[i];
    ++m[nr[i]];
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    sum -= (b * m[b]);
    sum += (c * m[b]);
    m[c] += m[b];
    m[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
