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