#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, ans = 0;
  ;
  cin >> n;
  vector<int> cnt(100002);
  for (int i = 0; i < (int)n; i++) {
    int a;
    cin >> a;
    cnt[a]++;
    ans += a;
  }
  cin >> q;
  vector<int> ver(q);
  for (int i = 0; i < (int)q; i++) {
    int b, c;
    cin >> b >> c;
    cnt[c] += cnt[b];
    ans += cnt[b] * (c - b);
    cnt[b] = 0;
    ver[i] = ans;
  }
  for (int i = 0; i < (int)q; i++) cout << ver[i] << endl;
  return 0;
}
