#include <bits/stdc++.h>
using namespace std;
int a[100001], t;
int main() {
  int n, q, x, y;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    t += x;
    a[x]++;
  }
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> x >> y;
    t -= (a[x] * x), t += (a[x] * y);
    a[y] += a[x], a[x] = 0;
    cout << t << endl;
  }
  return 0;
}
