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