#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q, B, C, sum = 0, f, s;
  map<int, int> count;
  cin >> N;
  vector<int> Ai(N);
  for (int i = 0; i < N; i++) {
    cin >> s;
    Ai.at(i) = s;
    sum += s;
    if (count.count(s)) {
      count.at(s) += 1;
    } else {
      count[s] = 1;
    }
  }
  cin >> Q;
  for (int j = 0; j < Q; j++) {
    cin >> B >> C;
    f = count[B];
    if (f == 0) {
      cout << sum << endl;
      continue;
    } else {
      sum = sum + (C - B) * f;
      count.erase(B);
      if (count.count(C)) {
        count.at(C) += f;
      } else {
        count[C] = f;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
