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