#include <bits/stdc++.h>
using namespace std;
int N, Cnt[100010], Sum;
int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    int Tmp;
    cin >> Tmp;
    Cnt[Tmp]++;
    Sum += Tmp;
  }
  int Q;
  cin >> Q;
  for (int i = 1; i <= Q; i++) {
    int B, C;
    cin >> B >> C;
    Sum -= 1ll * Cnt[B] * B;
    Sum += 1ll * Cnt[B] * C;
    Cnt[C] += Cnt[B];
    Cnt[B] = 0;
    cout << Sum << endl;
  }
  return 0;
}
