#include <bits/stdc++.h>
int main() {
  int n, q, a[100000], r[100000], i, b, c, all = 0;
  for (i = 0; i < 100000; i++) {
    r[i] = 0;
  }
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d %d", &b, &c);
    for (int j = 0; j < n; j++) {
      if (a[j] == b) a[j] = c;
    }
    for (int j = 0; j < n; j++) {
      all += a[j];
    }
    printf("%d", all);
    all = 0;
  }
  return 0;
}
