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