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