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