#include <bits/stdc++.h>
int compare(const void* a, const void* b) { return (*(int*)a) - (*(int*)b); }
char* itoa(int value, char* str, int radix);
char* ltoa(long long value, char* str, int radix);
int main() {
  long long int ans = 0;
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  int q;
  scanf("%d", &q);
  int b[q], c[q];
  for (int i = 0; i < q; i++) {
    scanf("%d %d", &b[i], &c[i]);
  }
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++) {
      if (a[j] == b[i]) {
        a[j] = c[i];
      }
      ans += a[j];
      if (j == n - 1) {
        printf("%lld\n", ans);
        ans = 0;
      }
    }
  }
  return 0;
}
