#include <bits/stdc++.h>
int sumA(int A[], int N) {
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += A[i];
  }
  return sum;
}
void change(int A[], int B[], int C[], int N, int i) {
  for (int k = 0; k < N; k++) {
    if (A[k] == B[i]) A[k] = C[i];
  }
}
int main() {
  int N, Q;
  int A[100001], B[100001], C[100001];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
  scanf("%d", &Q);
  for (int i = 0; i < Q; i++) {
    scanf("%d %d", &B[i], &C[i]);
  }
  long S[100001];
  for (int i = 0; i < Q; i++) {
    change(A, B, C, N, i);
    S[i] = sumA(A, N);
  }
  for (int i = 0; i < Q; i++) {
    printf("%ld\n", S[i]);
  }
}
