#include <bits/stdc++.h>
using namespace std;
int Set(int mask, int pos) { return mask = mask | (1 << pos); }
bool check(int mask, int pos) { return (bool)(mask & (1 << pos)); }
int arr[100005], cnt[100005];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int a, b, n;
  long long sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    cnt[arr[i]]++;
    sum += (long long)arr[i];
  }
  int q;
  cin >> q;
  while (q--) {
    cin >> a >> b;
    if (!cnt[a]) {
      cout << sum << endl;
      continue;
    }
    sum -= 1LL * cnt[a] * a;
    sum += 1LL * cnt[a] * b;
    cnt[b] += cnt[a];
    cout << sum << endl;
  }
  return 0;
}
