#include <bits/stdc++.h>
using namespace std;
int main() {
  uint64_t N, Q;
  cin >> N;
  uint64_t countnum[100002];
  uint64_t sum = 0;
  for (uint64_t i = 0; i < N; i++) {
    uint64_t temp;
    cin >> temp;
    sum += temp;
    countnum[temp] += 1;
  }
  cin >> Q;
  uint64_t Bi[100001];
  uint64_t Ci[100001];
  for (uint64_t i = 0; i < Q; i++) {
    cin >> Bi[i] >> Ci[i];
  }
  for (uint64_t i = 0; i < Q; ++i) {
    sum -= Bi[i] * countnum[Bi[i]];
    sum += Ci[i] * countnum[Bi[i]];
    cout << sum << endl;
    countnum[Ci[i]] += countnum[Bi[i]];
    countnum[Bi[i]] = 0;
  }
}
