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