#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  int counter[100000] = {};
  __int64_t sum = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    sum += a;
    counter[a]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    sum += counter[b] * (c - b);
    counter[c] += counter[b];
    counter[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
