#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, q;
int niz[maxn];
int cnt[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n;
  int zbir = 0;
  for (int i = 1; i <= n; i++) {
    cin >> niz[i];
    cnt[niz[i]]++;
    zbir += niz[i];
  }
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    zbir -= cnt[a] * a;
    cnt[b] += cnt[a];
    zbir += cnt[a] * b;
    cnt[a] = 0;
    cout << zbir << endl;
  }
  return 0;
}
