#include <bits/stdc++.h>
using namespace std;
long long occ[100005];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long S = 0;
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    occ[x] += 1;
    S += x;
  }
  long long Q;
  cin >> Q;
  while (Q--) {
    long long a, b;
    cin >> a >> b;
    S -= occ[a] * a;
    S += occ[a] * b;
    occ[b] += a;
    occ[a] = 0;
    cout << S << "\n";
  }
}
