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