#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  cin >> N;
  int A[100005];
  int64_t S = 0;
  for (int i = 0; i < N; i++) {
    int ts;
    cin >> ts;
    S += ts;
    A[ts]++;
  }
  cin >> Q;
  int B[Q], C[Q];
  for (int i = 0; i < Q; i++) {
    scanf("%d %d", &B[i], &C[i]);
  }
  for (int i = 0; i < Q; i++) {
    int kw;
    kw = A[B[i]];
    A[B[i]] = 0;
    A[C[i]] += kw;
    S = S + kw * (C[i] - B[i]);
    printf("%d\n", S);
  }
}
