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