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