#include <bits/stdc++.h>
int main() {
  int n, q, i, j, a, b;
  long long int s = 0;
  scanf("%d", &n);
  int ara[10 ^ 5];
  for (i = 0; i < n; i++) {
    scanf("%d", &ara[i]);
  }
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d%d", &a, &b);
    long long int s = 0;
    for (j = 0; j < n; j++) {
      if (ara[j] == a) {
        ara[j] = b;
      }
      s = s + ara[j];
    }
    printf("%lld\n", s);
  }
  return 0;
}
