#include <bits/stdc++.h>
using namespace std;
long long pw(long long a, long long b) {
  if (b == 0) return 1;
  long long t = pw(a, b / 2);
  if (b % 2 == 0)
    return (t * t) % 1000000007;
  else
    return ((t * t) % 1000000007 * a) % 1000000007;
}
int main() {
  int n;
  cin >> n;
  int sum = 0;
  map<int, int> make_pair;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    make_pair[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum -= b * make_pair[b];
    sum += c * make_pair[b];
    make_pair[c] += make_pair[b];
    make_pair.erase(b);
    cout << sum << endl;
  }
}
