#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int m, sum = 0, k = 0, i, d = 0, j, sum1 = 0, sum2 = 0, sum3 = 0, l,
                   kk, sum4 = 0, sum5 = 0, sum6 = 0, c = 0, x, y, q;
  long long int n;
  cin >> n;
  long long int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  map<long long int, long long int> mp;
  for (i = 0; i < n; i++) mp[a[i]]++;
  cin >> q;
  while (q--) {
    cin >> x >> y;
    long long int z = mp[x];
    sum -= mp[x] * x;
    mp.erase(mp[x]);
    sum += y * z;
    mp[y] += z;
    cout << sum << endl;
  }
}
