#include <bits/stdc++.h>
using namespace std;
int z[111111];
int main() {
  int n, k, ba = 0;
  cin >> n;
  while (n--) {
    int a;
    cin >> a;
    ba += a;
    z[a]++;
  }
  cin >> k;
  while (k--) {
    int a, b;
    cin >> a >> b;
    ba += z[a] * (b - a);
    z[b] += z[a];
    z[a] = 0;
    cout << ba << endl;
  }
  return 0;
}
