#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> cnt(100001);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    ++cnt[A[i]];
  }
  int Q;
  cin >> Q;
  vector<long long> ans(Q);
  for (int i = 0; i < Q; ++i) {
    int B, C;
    cin >> B >> C;
    cnt[C] += cnt[B];
    cnt[B] = 0;
    for (int j = 0; j < cnt.size(); ++j) {
      if (cnt[j] == 0) continue;
      ans[i] += j * cnt[j];
    }
  }
  for (int i = 0; i < Q; ++i) cout << ans[i] << endl;
}
