#include <bits/stdc++.h>
int main(void) {
  long int n, q;
  long int a[100001];
  long int b, c;
  if (fscanf(stdin, "%ld", &n) == EOF) return 1;
  for (int i = 0; i < n; i++) {
    if (fscanf(stdin, "%ld", a + i) == EOF) return 1;
  }
  if (fscanf(stdin, "%ld", &q) == EOF) return 1;
  for (int i = 0; i < q; i++) {
    long int ans = 0;
    if (fscanf(stdin, "%ld %ld", &b, &c) == EOF) return 1;
    for (int j = 0; j < n; j++) {
      if (a[j] == b) a[j] = c;
      ans += a[j];
    }
    printf("%ld\n", ans);
  }
  return 0;
}
