#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  long long ans = 0;
  unordered_map<int, int> umap;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    ans += t;
    if (umap.find(t) == umap.end()) {
      umap[t] = 1;
    } else {
      umap[t]++;
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    if (umap.find(b) == umap.end()) {
      cout << ans << endl;
      continue;
    }
    int tmp = umap[b];
    ans = (ans - tmp * b) + tmp * c;
    cout << ans << endl;
    umap.erase(b);
    if (umap.find(c) == umap.end())
      umap[c] = tmp;
    else
      umap[c] += tmp;
  }
  return 0;
}
