#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (auto &a : A) cin >> a;
  int64_t S = 0;
  vector<int> D(int(1e5 + 1));
  for (auto &a : A) {
    D[a]++;
    S += a;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    S -= b * D[b];
    S += c * D[b];
    D[c] += D[b];
    D[b] = 0;
    cout << S << endl;
  }
}
