#include <bits/stdc++.h>
int main() {
  long long int N, i;
  scanf("%lld", &N);
  long long int a[N], x = 0;
  for (i = 0; i < N; i++) {
    scanf("%lld", &a[i]);
    x = x + a[i];
  }
  long long int Q;
  scanf("%lld", &Q);
  long long int B, C, y;
  int j;
  for (j = 1; j <= Q; j++) {
    scanf("%lld%lld", &B, &C);
    for (i = 0; i < N; i++) {
      if (a[i] == B) {
        x = x - a[i];
        a[i] = C;
        x = x + a[i];
      }
    }
    printf("%lld\n", x);
  }
}
