#include <bits/stdc++.h>
using namespace std;
unordered_map<int, int> m;
int main(int argc, char *argv[]) {
  int n, q;
  int sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    m[v]++;
    sum += v;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    int change = (b - a) * m[a];
    m[b] += m[a];
    m[a] = 0;
    sum += change;
    cout << sum << endl;
  }
  return 0;
}
