#include <bits/stdc++.h>
using namespace std;
signed main() {
  int n, a;
  vector<int> v;
  map<int, int> d;
  int q, b, c, sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    sum += a;
    d[a]++;
    if (d[a] == 1) v.push_back(a);
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    sum += ((c - b) * d[b]);
    d[c] += d[b];
    d[b] = 0;
    cout << sum << "\n";
  }
}
