#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N], cnt[N];
int main() {
  int n;
  cin >> n;
  int res = 0;
  for (int i = 0; i < n; ++i) cin >> a[i], cnt[a[i]]++, res += a[i];
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    res += (c - b) * cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << res << '\n';
  }
  return 0;
}
