#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int sm = 0;
  int cnt[100000];
  memset(cnt, 0, sizeof(cnt));
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sm += a[i];
    cnt[a[i]]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    ;
    sm -= cnt[x] * x;
    sm += cnt[x] * y;
    cnt[y] += cnt[x];
    cnt[x] = 0;
    cout << sm << endl;
  }
}
