#include <bits/stdc++.h>
int max(int a, int b) {
  if (a > b)
    return a;
  else
    return b;
}
int min(int a, int b) {
  if (a < b)
    return a;
  else
    return b;
}
int sort(const void *a, const void *b) { return *(int *)a - *(int *)b; }
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];
  long long sum;
  for (int i = 0; i < q; ++i) {
    sum = 0;
    scanf("%d%d", &b[i], &c[i]);
    for (int j = 0; j < n; ++j) {
      if (a[j] == b[i]) a[j] = c[i];
      sum += a[j];
    }
    printf("%lld\n", sum);
  }
  return 0;
}
