#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, q;
  vector<long long> a(100010, 0), b(100010, 0), c(100010, 0);
  vector<long long> count(100010, 0);
  cin >> n;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    count[a[i]]++;
  }
  cin >> q;
  for (int j = 0; j < (int)(q); j++) {
    cin >> b[j] >> c[j];
  }
  long long res = 0;
  for (int k = 0; k < (int)(10010); k++) {
    res += count[k] * k;
  }
  for (int j = 0; j < (int)(q); j++) {
    res += count[b[j]] * (c[j] - b[j]);
    count[c[j]] += count.at(b[j]);
    count[b[j]] = 0;
    cout << res << endl;
  }
}
