#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  t = 1;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    map<int, int> m;
    long long int sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      m[a[i]]++;
      sum += a[i];
    }
    int q;
    cin >> q;
    while (q--) {
      int val, chg;
      cin >> val >> chg;
      if (m[val] > 0) {
        int fre = m[val];
        sum = sum - (fre * val);
        sum += (fre * chg);
        if (m[chg] > 0) {
          m[chg] = m[chg] + m[val];
        } else
          m[chg] = fre;
        m[val] = 0;
      }
      cout << sum << endl;
    }
  }
}
