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