#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  vector<int> a(n);
  map<int, int> mp;
  long sum = 0;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    mp[a[i]]++;
    sum += a[i];
  }
  int k;
  cin >> k;
  vector<int> b(k);
  vector<int> c(k);
  for (int i = 0; i < (int)(k); i++) cin >> b[i] >> c[i];
  for (int i = 0; i < (int)(k); i++) {
    if (mp[b[i]] > 0) {
      sum -= b[i] * mp[b[i]];
      sum += c[i] * mp[b[i]];
      mp[c[i]] += mp[b[i]];
      mp[b[i]] = 0;
      cout << sum << endl;
    } else {
      cout << sum << endl;
    }
  }
  return (0);
}
