#include <bits/stdc++.h>
using namespace std;
string str;
const int tt = 0;
void solve() {
  int m, n, a, b, c;
  cin >> n;
  map<int, int> make_pair;
  long long sum = 0;
  for (int i = 0; i < (int)n; i++) {
    cin >> a;
    make_pair[a]++;
    sum += a;
  }
  cin >> c;
  while (c--) {
    cin >> a >> b;
    long long rem = make_pair[a];
    rem *= a;
    long long add = make_pair[a] * b;
    make_pair[b] += make_pair[a];
    make_pair[a] = 0;
    sum += add;
    sum -= rem;
    cout << sum << endl;
    ;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  if (tt) {
    int t;
    cin >> t;
    while (t--) {
      solve();
    }
  } else {
    solve();
  }
  return 0;
}
