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