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