#include <bits/stdc++.h>
using namespace std;
int cnt[100000 + 7] = {};
int N, Q;
void solve() {
  cin >> N;
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    int inp;
    cin >> inp;
    sum += inp;
    cnt[inp]++;
  }
  cin >> Q;
  while (Q--) {
    int B, C;
    cin >> B >> C;
    sum = sum + (C - B) * cnt[B];
    cnt[C] += cnt[B];
    cout << sum << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
