#include <bits/stdc++.h>
using namespace std;
const int limit = 100000;
int a[limit], b[limit], c[limit];
int main(void) {
  int N, Q;
  cin >> N;
  for (int i = 0; i < N; i++) cin >> a[i];
  cin >> Q;
  for (int i = 0; i < N; i++) cin >> b[i] >> c[i];
  long long S = 0;
  for (int i = 0; i < N; i++) {
    S += a[i];
  }
  for (int i = 0; i < Q; i++) {
    for (int j = 0; j < N; j++) {
      if (b[i] == a[j]) {
        a[j] = c[i];
        S += c[i] - b[i];
      }
    }
    cout << S << endl;
  }
}
