#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, q, g;
  g = 0;
  map<int, int> bro;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> m;
    if (bro.count(m)) {
      bro[m] += 1;
    } else {
      bro[m] = 1;
    }
    g += m;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    if (bro.count(b)) {
      g += bro[b] * (c - b);
      if (bro.count(c)) {
        bro[c] += bro[b];
        bro[b] = 0;
      } else {
        bro[c] = bro[b];
        bro[b] = 0;
      }
    }
    cout << g << endl;
  }
}
