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