#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  map<long long, long long> mp;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    mp[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  while (q--) {
    long long x, y;
    cin >> x >> y;
    if (mp[x]) {
      sum -= (x * mp[x]);
      sum += (y * mp[x]);
      mp[y] += mp[x];
    }
    cout << sum << endl;
  }
  return 0;
}
