#include <bits/stdc++.h>
int main() {
  int n, sum = 0;
  scanf("%d", &n);
  int arr[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    sum += arr[i];
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int s, t;
    scanf("%d %d", &s, &t);
    for (int i = 0; i < n; i++) {
      if (arr[i] == s) {
        sum = sum - s + t;
        arr[i] = t;
      }
    }
    printf("%d\n", sum);
  }
  return 0;
}
