#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int a[n];
  int cnt[100001] = {0};
  long s = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    s += a[i];
  }
  int q;
  cin >> q;
  int b, c;
  while (q--) {
    cin >> b >> c;
    s += ((c - b) * cnt[b]);
    cout << s << endl;
    cnt[b] = 0;
    cnt[c] += cnt[b];
  }
}
