#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int basesum = 0;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    basesum += a[i];
  }
  int q;
  cin >> q;
  vector<int> b(q);
  vector<int> c(q);
  for (int i = 0; i < (int)(q); i++) {
    cin >> b[i] >> c[i];
  }
  vector<int> sum(q);
  for (int i = 0; i < (int)(n); i++) {
    for (int j = 0; j < (int)(q); j++) {
      if (a[i] == b[j]) {
        a[i] = c[j];
        sum[j] += a[i] - b[j];
      }
    }
  }
  for (int i = 0; i < (int)(q); i++) {
    cout << basesum + sum[i] << endl;
  }
}
