#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  int sum = 0;
  map<int, int> m;
  for (long long i = (0), ixxxx_end = (N); i < ixxxx_end; ++i) {
    int a;
    cin >> a;
    m[a]++;
    sum += a;
  }
  int Q;
  cin >> Q;
  vector<int> ans(Q);
  for (long long i = (0), ixxxx_end = (Q); i < ixxxx_end; ++i) {
    int b, c;
    cin >> b >> c;
    sum += c * m[b] - b * m[b];
    m[c] += m[b];
    m[b] = 0;
    ans[i] = sum;
  }
  for (long long i = (0), ixxxx_end = (Q); i < ixxxx_end; ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}
