#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[N];
  long long total = 0;
  for (int a = 0; a < N; a++) {
    cin >> A[a];
    total += A[a];
  }
  int cnt[100001];
  memset(cnt, 0, sizeof(cnt));
  for (int a = 0; a < N; a++) cnt[A[a]]++;
  int Q;
  cin >> Q;
  for (int a = 0; a < Q; a++) {
    int B, C;
    cin >> B >> C;
    total -= cnt[B] * B;
    total += cnt[B] * C;
    cnt[C] += cnt[B];
    cnt[B] = 0;
    cout << total << endl;
  }
}
