#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, i, q, b, c, sum = 0;
  map<long long, long long> mp;
  cin >> n;
  long long a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    mp[a[i]]++;
  }
  cin >> q;
  for (i = 0; i < q; i++) {
    long long currsum;
    cin >> b >> c;
    if (mp.find(b) != mp.end()) {
      long long x = mp[b];
      currsum = sum - x * b + x * c;
      sum = currsum;
      replace(a, a + n, b, c);
      mp.erase(b);
      if (mp.find(c) != mp.end())
        mp[c] += x;
      else
        mp[c] = x;
    } else
      currsum = sum;
    cout << currsum << "\n";
  }
  return 0;
}
