#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> a;
  int tmp, ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    ans += tmp;
    if (a.count(tmp))
      a.at(tmp)++;
    else
      a[tmp] = 1;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    if (a.count(tmp1)) {
      if (a.count(tmp2)) {
        a.at(tmp2) += a.at(tmp1);
        ans -= tmp1 * a.at(tmp1);
        ans += tmp2 * a.at(tmp1);
        a.at(tmp1) = 0;
      } else {
        a[tmp2] = 0;
        a.at(tmp2) += a.at(tmp1);
        ans -= tmp1 * a.at(tmp1);
        ans += tmp2 * a.at(tmp1);
        a.at(tmp1) = 0;
      }
    }
    cout << ans << endl;
  }
}
