#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, q, sum = 0, b, k;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> k;
  for (int i = 0; i < k; i++) {
    sum = 0;
    cin >> b >> q;
    for (int j = 0; j < n; j++) {
      if (b == a[j]) a[j] = q;
      sum = sum + a[j];
    }
    cout << sum << "\n";
  }
  return 0;
}
