#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
  int n;
  cin >> n;
  map<long long, long long> mp;
  long long s = 0;
  for (int i = 0; i < n; ++i) {
    long long t;
    cin >> t;
    if (mp.find(t) != mp.end()) {
      ++mp[t];
    } else {
      mp[t] = 1;
    }
    s += t;
  }
  int q;
  cin >> q;
  for (int j = 0; j < q; ++j) {
    long long b, c;
    cin >> b >> c;
    if (mp.find(b) != mp.end()) {
      s += (c - b) * mp[b];
      if (mp.find(c) != mp.end()) {
        mp[c] += mp[b];
        mp[b] = 0;
      } else {
        mp[c] = mp[b];
      }
    }
    cout << s << endl;
  }
  return 0;
}
