#include <bits/stdc++.h>
using namespace std;
int main() {
  int n1, n2, a[100000];
  cin >> n1;
  for (int i = 0; i < n1; i++) cin >> a[i];
  cin >> n2;
  for (int j = 0; j < n2; j++) {
    int x, y, tong = 0;
    cin >> x >> y;
    for (int i = 0; i < n1; i++)
      if (a[i] == x) {
        tong += y;
        a[i] = y;
      } else
        tong += a[i];
    cout << tong << endl;
  }
}
