#include <bits/stdc++.h>
using namespace std;
long long z, o, ans;
long long N = 1e9 + 7;
int code() {
  long long n;
  cin >> n;
  long long a[n];
  long long sum = 0;
  vector<int> vc(1e5 + 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    vc[a[i]]++;
    sum += a[i];
  }
  int u;
  cin >> u;
  for (int i = 0; i < u; i++) {
    int a1, a2;
    cin >> a1 >> a2;
    if (vc[a1] > 0) {
      if (a1 >= a2) {
        sum -= (a1 * vc[a1]) - (a2 * vc[a1]);
        vc[a2] = vc[a1];
        vc[a1] = 0;
      } else {
        sum += (a2 * vc[a1]) - (a1 * vc[a1]);
        vc[a2] = vc[a1];
        vc[a1] = 0;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tjk = 1;
  while (tjk--) {
    code();
  }
}
