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