#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int> mp;
  int n, q, a, b, c;
  int i, j, k;
  unsigned long tmp = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a;
    mp[a]++;
    tmp += a;
  }
  cin >> q;
  unsigned long *ans = new unsigned long[q];
  for (i = 0; i < q; i++) {
    cin >> b >> c;
    tmp -= b * mp[b];
    tmp += c * mp[b];
    mp[c] += mp[b];
    mp[b] = 0;
    ans[i] = tmp;
  }
  for (i = 0; i < q; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
