#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0, i_len = (N); i < i_len; ++i) cin >> A[i];
  int Q;
  cin >> Q;
  int B, C;
  vector<int> ansVec;
  sort(A.begin(), A.end());
  for (int i = 0, i_len = (Q); i < i_len; ++i) {
    cin >> B >> C;
    int cnt = 0;
    for (int j = 0, j_len = (N); j < j_len; ++j) {
      if (A[j] == B) {
        A[j] = C;
        cnt++;
        continue;
      } else if (cnt > 0)
        break;
    }
    int ans = 0;
    for (int a : A) {
      ans += a;
    }
    ansVec.push_back(ans);
  }
  for (int an : ansVec) cout << an << endl;
  return 0;
}
