#include <bits/stdc++.h>
int main() {
  int i, j;
  long lN;
  long aryNum[100005] = {0};
  scanf("%ld", &lN);
  long lA[lN];
  for (long i = 0; i < lN; i++) {
    scanf("%ld", &lA[i]);
  }
  long lQ;
  scanf("%ld", &lQ);
  long lBC[lQ][2];
  for (long i = 0; i < lQ; i++) {
    for (int j = 0; j < 2; j++) {
      scanf("%ld", &(lBC[i][j]));
    }
  }
  for (long i = 0; i < lN; i++) {
    aryNum[lA[i]] += 1;
  }
  for (long i = 0; i < lQ; i++) {
    aryNum[lBC[i][1]] += aryNum[lBC[i][0]];
    aryNum[lBC[i][0]] = 0;
    long strRet = 0;
    for (long j = 0; j < 100005; j++) {
      if (aryNum[j] > 0) {
        strRet += j * aryNum[j];
      }
    }
    printf("%ld\n", strRet);
  }
  return 0;
}
