#include <bits/stdc++.h>
using namespace std;
int n, q, a[100002], c, b, s, x, y;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    a[x]++;
    s += x;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    s += (c - b) * a[b];
    cout << s << endl;
    a[c] += a[b];
    a[b] = 0;
  }
  return 0;
}
