#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[100000], i, q, m, n1, suma[100000], cnt = 0;
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  for (int j = 1; j <= q; j++) {
    cin >> n1 >> m;
    int sum = 0;
    for (i = 0; i < n; i++) {
      if (a[i] == n1) {
        a[i] = m;
        sum += a[i];
      } else
        sum += a[i];
    }
    suma[cnt++] = sum;
  }
  for (i = 0; i < cnt; i++) cout << suma[i] << endl;
  return 0;
}
