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