#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, q;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  cin >> q;
  while (q--) {
    int n1, r1;
    cin >> n1 >> r1;
    long long sum = 0;
    for (int i = 0; i < n; i++) {
      if (arr[i] == n1) {
        arr[i] = r1;
        sum = sum + r1;
      } else {
        sum = sum + arr[i];
      }
    }
    cout << sum << "\n";
  }
}
