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