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