#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  solve();
  return 0;
}
void solve() {
  int n, q;
  cin >> n;
  map<int, int> M;
  long long total = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    M[a]++;
    total += a;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    if (M.count(b)) {
      int cnt = M[b];
      M[b] = 0;
      M[c] += cnt;
      total -= cnt * b;
      total += cnt * c;
      cout << total << endl;
    } else
      cout << total << endl;
  }
}
