#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, b, c;
  long long q;
  cin >> n;
  long long a[n];
  long long i, j;
  for (i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  long long s = accumulate(a, a + n, 0);
  for (i = 0; i < q; i++) {
    cin >> b >> c;
    for (j = 0; j < n; j++) {
      if (a[j] == b) {
        a[j] = c;
        s = s - b + c;
      }
    }
    cout << s << "\n";
  }
}
