#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n];
  for (int i = 0; i < (n); i++) cin >> a[i];
  ;
  sort(a, a + n);
  long long q;
  cin >> q;
  unsigned long long b[q], c[q], s[q];
  for (int i = 0; i < (q); i++) {
    cin >> b[i] >> c[i];
    s[i] = 0;
  }
  unsigned long long sum;
  long long j;
  for (int i = 0; i < (q); i++) {
    j = 0;
    while (a[j] <= b[i]) {
      if (a[j] == b[i]) a[j] = c[i];
      j++;
    }
    sum = 0;
    for (int i = 0; i < (n); i++) {
      sum += a[i];
    }
    cout << sum << endl;
  }
}
