#include <bits/stdc++.h>
using namespace std;
void YN(bool flg) {
  if (flg)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
void Yn(bool flg) {
  if (flg)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
void yn(bool flg) {
  if (flg)
    cout << "yes" << endl;
  else
    cout << "no" << endl;
}
int main() {
  int n;
  cin >> n;
  vector<long long> cnt(100005);
  for (int i = 0; i < (int)(n); i++) {
    int a;
    cin >> a;
    cnt[a]++;
  }
  long long sum = 0;
  for (int i = 0; i < (int)(100005); i++) sum += i * cnt[i];
  int q;
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    long long b, c;
    cin >> b >> c;
    if (cnt[b] != 0) {
      sum += (c - b) * cnt[b];
      cnt[b] = 0;
      cnt[c] += cnt[b];
    }
    cout << sum << endl;
  }
  return 0;
}
