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