#include <bits/stdc++.h>
int main(void) {
  int num[10010];
  long long int sum = 0;
  int seq, treat, tmp1, tmp2;
  scanf("%d", &seq);
  for (int i = 1; i <= seq; i++) {
    scanf("%d", &num[i]);
    sum += num[i];
  }
  scanf("%d", &treat);
  for (int i = 0; i < treat; i++) {
    scanf("%d%d", &tmp1, &tmp2);
    for (int j = 1; j <= seq; j++) {
      if (num[j] == tmp1) {
        sum = sum + tmp2 - tmp1;
        num[j] = tmp2;
      }
    }
    printf("%lld\n", sum);
  }
  return 0;
}
