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