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