#include <bits/stdc++.h>
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
using namespace std;
void solve() {
  int n, s = 0;
  map<int, int> make_pair;
  cin >> n;
  for (int i = 0, x; i < n; ++i) {
    cin >> x;
    s += x;
    make_pair[x]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    s = s - (b * make_pair[b]);
    s = s + (c * make_pair[b]);
    make_pair[c] += make_pair[b];
    make_pair[b] = 0;
    cout << s << endl;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
