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