#include <bits/stdc++.h>
int main() {
  int n;
  long long int sum;
  int *ap, *kp;
  scanf("%d", &n);
  ap = (int *)calloc(n, sizeof(int));
  kp = ap;
  for (int i = 0; i < n; i++) {
    scanf("%d", kp);
    kp++;
  }
  int q;
  scanf("%d", &q);
  kp = ap;
  int b, c;
  for (int i = 0; i < q; i++) {
    sum = 0;
    scanf("%d %d", &b, &c);
    for (int j = 0; j < n; j++) {
      if (*kp == b) *kp = c;
      sum += *kp;
      kp++;
    }
    printf("%d\n", sum);
    kp = ap;
  }
  return 0;
}
