#include <bits/stdc++.h>
int main() {
  int a[100000], b[400000], n, k, i = 0;
  scanf("%d", &n);
  for (; i < n; i++) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &k);
  for (int j = 0; j < 2 * k; j++) {
    scanf("%d", &b[j]);
  }
  for (int m = 0; m < 2 * k; m = m + 2) {
    int sum = 0;
    for (int l = 0; l < n; l++) {
      if (b[m] == a[l]) {
        a[l] = b[m + 1];
        sum = sum + a[l];
      } else {
        sum = sum + a[l];
      }
    }
    printf("%d\n", sum);
  }
  return 0;
}
