#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  map<long long, long long> mp;
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n))) {
    cin >> v[i];
    mp[v[i]]++;
  }
  long long sum = accumulate(begin(v), end(v), 0);
  long long q;
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    long long cpt = mp[b];
    sum -= (1LL * b * cpt);
    sum += (1LL * c * cpt);
    mp[b] = 0;
    mp[c] += cpt;
    cout << sum << endl;
  }
  return 0;
}
