#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
long long int powmod(long long int a, long long int b) {
  long long int res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int nxt() {
  int x;
  scanf("%d", &x);
  return x;
}
int main() {
  int w, x, y, z, zn;
  cin >> w;
  multiset<int> seq;
  int sum = 0;
  for (int i = 0; i < w; i++) {
    cin >> x;
    seq.insert(x);
    sum += x;
  }
  int diff;
  int count;
  cin >> y;
  for (int j = 0; j < y; j++) {
    cin >> z >> zn;
    diff = zn - z;
    count = seq.count(z);
    sum = sum + (diff * count);
    cout << sum << "\n";
    seq.erase(z);
    for (int k = 0; k < count; k++) {
      seq.insert(zn);
    }
  }
}
