#include <bits/stdc++.h>
using namespace std;
void Main() {
  int64_t N;
  cin >> (N);
  vector<int64_t> A(N);
  for (int i = 0; i < (int)(N); i++) cin >> (A[i]);
  int64_t Q;
  cin >> (Q);
  vector<int64_t> B(Q);
  vector<int64_t> C(Q);
  for (int i = 0; i < (int)(Q); i++) {
    cin >> (B[i]);
    cin >> (C[i]);
  }
  sort(A.begin(), A.end());
  bool tar = false;
  for (int i = 0; i < (int)(Q); i++) {
    for (int j = 0; j < (int)(N); j++) {
      if (A[j] == B[i])
        tar = true;
      else
        tar = false;
      if (tar) A[j] = C[i];
    }
    cout << ((int64_t)accumulate(A.begin(), A.end(), 0)) << "\n";
  }
}
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  Main();
  return 0;
}
