#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  map<int, int> m;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    sum += t;
    m[t]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b;
    cin >> b;
    int c;
    cin >> c;
    if (m[b] > 0) {
      int remove = b * m[b];
      sum -= remove;
      sum += c * m[b];
      m[c] += m[b];
      m[b] = 0;
    }
    cout << sum << endl;
  }
}
int main() {
  solve();
  return 0;
}
