#include <bits/stdc++.h>
using namespace std;
int a[100010], cnt[100010], sum, n, q, b, c;
int main() {
  cin >> n;
  int i, j, k;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    sum += a[i];
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    cnt[c] += cnt[b];
    sum = sum + cnt[b] * (c - b);
    cnt[b] = 0;
    cout << sum << endl;
  }
}
