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