#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < (n); ++i) {
    cin >> vec.at(i);
  }
  int q;
  cin >> q;
  int b, c;
  for (int i = 0; i < (q); ++i) {
    cin >> b >> c;
    int sum = 0;
    for (int k = 0; k < (n); ++k) {
      if (vec.at(k) == b) {
        sum += c;
        vec.at(k) = c;
      } else {
        sum += vec.at(k);
      }
    }
    cout << sum << endl;
  }
}
