#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int num[n];
  for (int i = 0; i < n; i++) {
    cin >> num[i];
  }
  int q;
  cin >> q;
  vector<int> arr[q];
  while (q--) {
    int b;
    int c;
    cin >> b >> c;
    int sum = 0;
    for (int i = 0; i < n; i++) {
      if (num[i] == b) {
        sum = sum + c;
        num[i] = c;
      } else
        sum = sum + num[i];
    }
    cout << sum << endl;
  }
}
