#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> f(100003, 0);
  long long int res = 0;
  for (int i = 0; i <= n - 1; i++) {
    cin >> a[i];
    f[a[i]]++;
    res += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    res += f[b] * (c - b);
    f[c] += f[b];
    cout << res << "\n";
  }
  return 0;
}
