#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10, MOD = 1e9 + 7, INF = 1e9 + 5;
int cnt[MAXN];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int in, n;
  long long sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> in;
    cnt[in]++;
    sum += in;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum -= b * cnt[b];
    sum += cnt[b] * c;
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << sum << '\n';
  }
}
