#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long a[n];
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long t;
  cin >> t;
  while (t--) {
    long long c, b;
    cin >> c >> b;
    long long cnt = 0;
    for (long long i = 0; i < n; i++) {
      if (a[i] == c) {
        cnt++;
        a[i] = b;
      }
    }
    sum -= cnt * c;
    sum += b * cnt;
    cout << sum << '\n';
  }
  {}
}
