#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  map<int, int> quant;
  long long int n, q, total = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int r;
    cin >> r;
    if (quant.find(r) == quant.end()) quant[r] = 0;
    quant[r] += 1;
    total += r;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    if (quant.find(a) != quant.end()) {
      int cont = quant[a];
      total = total - (a * cont);
      quant[a] = 0;
      if (quant.find(b) == quant.end())
        quant[b] = cont;
      else
        quant[b] += cont;
      total = total + (b * cont);
    }
    cout << total << endl;
  }
  return 0;
}
