#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int cnt[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int a[n + 5];
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum = sum - (b * cnt[b]) + (c * cnt[b]);
    cout << sum << endl;
    cnt[c] += cnt[b];
    cnt[b] = 0;
  }
  return 0;
}
