#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;
    a[tmp]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    a[tmp2] += a[tmp1];
    ans -= tmp1 * a.at(tmp1);
    ans += tmp2 * a.at(tmp1);
    a.at(tmp1) = 0;
    cout << ans << endl;
  }
}
