#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long N, Q, answe = 0;
  cin >> N;
  long long A[N], M[100001];
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
    M[A[i]]++;
    answe += A[i];
  }
  cin >> Q;
  long long B, C, ans[Q];
  ans[0] = answe;
  for (long long i = 0; i < Q; i++) {
    cin >> B >> C;
    if (M[B] >= 1) {
      if (i > 0) {
        ans[i] = ans[i - 1] + M[B] * (C - B);
      } else {
        ans[i] = ans[0] + M[B] * (C - B);
      }
      M[C] += M[B];
      M[B] = 0;
    } else {
      if (i > 0) {
        ans[i] = ans[i - 1];
      } else {
        ans[i] = answe;
      }
    }
  }
  for (long long i = 0; i < Q; i++) {
    cout << ans[i] << endl;
  }
}
