#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, s{};
  cin >> N;
  unordered_map<int, int> valCnt{};
  for (int i = 0; i < N; ++i) {
    int v{};
    cin >> v;
    s += v;
    valCnt[v]++;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    int b, c;
    cin >> b >> c;
    int cnt = valCnt[b];
    s = s + (cnt * (c - b));
    valCnt[c] += valCnt[b];
    valCnt[b] = 0;
    cout << s << endl;
  }
  return 0;
}
