#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int q;
  cin >> q;
  vector<int> b(q), c(q);
  for (int i = 0; i < q; ++i) {
    cin >> b[i] >> c[i];
  }
  int64_t sum = 0;
  map<int, int> mm;
  for (int i = 0; i < n; ++i) {
    mm[a[i]]++;
    sum += a[i];
  }
  for (int i = 0; i < q; ++i) {
    int beforecount = mm[b[i]];
    mm.erase(b[i]);
    mm[c[i]] += beforecount;
    sum -= b[i] * beforecount;
    sum += c[i] * beforecount;
    cout << sum << endl;
  }
}
