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