#include <bits/stdc++.h>
using namespace std;
int main() {
  const long long MAX = 1e5 + 1;
  long long n;
  cin >> n;
  vector<long long> a(MAX);
  for (long long i = 0; i < n; i++) {
    long long tmp;
    cin >> tmp;
    a[tmp]++;
  }
  long long q;
  cin >> q;
  vector<long long> b(q);
  vector<long long> c(q);
  for (long long i = 0; i < q; i++) {
    cin >> b[i];
    cin >> c[i];
  }
  for (long long i = 0; i < q; i++) {
    long long ans = 0;
    if (a[b[i]] > 0) {
      long long num = a[b[i]];
      a[b[i]] = 0;
      a[c[i]] += num;
    }
    for (long long j = 1; j < MAX; j++) {
      ans += a[j] * j;
    }
    cout << ans << endl;
  }
  return 0;
}
