#include <bits/stdc++.h>
using namespace std;
void test_case() {
  int n, t1 = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> t1;
    a.push_back(t1);
  }
  int q, t2 = 0, t3 = 0;
  cin >> q;
  vector<int> b, c;
  for (int i = 0; i < q; ++i) {
    cin >> t2 >> t3;
    b.push_back(t2);
    c.push_back(t3);
  }
  vector<int> s(n);
  vector<int>::iterator it;
  for (int i = 0; i < q; ++i) {
    if (it != a.end()) {
      it = find(b.begin(), b.end(), a[i]);
      int h = it - a.begin();
      a[i] = c[h];
      cout << accumulate(a.begin(), a.end(), 0) << "\n";
    } else
      continue;
  }
}
int main() {
  test_case();
  return 0;
}
