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