#include <bits/stdc++.h>
using namespace std;
int cnt[100005];
int main() {
  int ans = 0;
  int n, b, c, q;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int tmp;
    cin >> tmp;
    cnt[tmp]++;
    ans += tmp;
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> b >> c;
    int num = cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    ans = ans + (c - b) * num;
    cout << ans << endl;
  }
  return 0;
}
