#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j, n, k = 0, x, y, q;
  cin >> n;
  long long a[n];
  unordered_map<long long, long long> mp;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
    k += a[i];
  }
  cin >> q;
  while (q--) {
    cin >> x >> y;
    if (mp.find(x) != mp.end()) {
      j = mp[x];
      while (mp[x]--) mp[y]++;
      k -= x * j;
      k += y * j;
    }
    cout << k << endl;
  }
}
