#include <bits/stdc++.h>
using namespace std;
void input(vector<long long>& v, long long n) {
  long long i, io;
  for (i = 0; i < n; i++) {
    cin >> io;
    v.push_back(io);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, i, q, sum = 0, sum1 = 0;
  cin >> n;
  vector<long long> v;
  input(v, n);
  for (i = 0; i < n; i++) sum1 += v.at(i);
  cin >> q;
  while (q--) {
    sum1 = sum;
    long long a, b;
    cin >> a >> b;
    long long k = *min_element(v.begin(), v.end());
    long long o = *max_element(v.begin(), v.end());
    if (a < k or a > o)
      cout << sum1 << endl;
    else {
      sum = 0;
      for (i = 0; i < n; i++) {
        if (v.at(i) == a) v.at(i) = b;
        sum += v.at(i);
      }
      cout << sum << endl;
    }
  }
}
