#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  int Q;
  cin >> Q;
  for (int j = 0; j < Q; j++) {
    int B, C;
    cin >> B >> C;
    for (int k = 0; k < N; k++) {
      if (A.at(k) > B) {
        sort(A.begin(), A.end());
        break;
      } else if (A.at(k) == B) {
        A.at(k) = C;
      }
    }
    int g = 0;
    for (int m = 0; m < N; m++) {
      g += A.at(m);
    }
    cout << g << endl;
  }
}
