#include <bits/stdc++.h>
int main() {
  int A[100000] = {0};
  int N = 0;
  int Q = 0;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    int num = 0;
    scanf("%d ", &num);
    A[i] = num;
  }
  scanf("%d", &Q);
  for (int j = 0; j < Q; j++) {
    int b = 0;
    int c = 0;
    int sum = 0;
    scanf("%d %d", &b, &c);
    for (int i = 0; i < N; i++) {
      if (b == A[i]) {
        A[i] = c;
      }
      sum += A[i];
    }
    printf("%d\n", sum);
  }
}
