#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
int main(void) {
  ios::sync_with_stdio(false);
  int n, b, c, s, i, q;
  int a[MAXN];
  cin >> n;
  for (s = i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    for (i = 0; i < n; i++)
      if (a[i] == b) {
        s += c - b;
        a[i] = c;
      }
    cout << s << '\n';
  }
  return 0;
}
