#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  long long n;
  cin >> n;
  long long sum{0};
  vector<int> a(n);
  for (long long i = 0; i < long long(n); i++) {
    cin >> a[i];
    sum += a[i];
  }
  int q;
  cin >> q;
  vector<int> b(q);
  vector<int> c(q);
  for (long long i = 0; i < long long(q); i++) {
    cin >> b[i];
    cin >> c[i];
  }
  for (long long i = 0; i < long long(q); i++) {
    sort(a.begin(), a.end());
    int count{0};
    for (long long j = 0; j < long long(n); j++) {
      if (a[j] == b[i]) {
        a[j] = c[i];
        count++;
      } else if (a[j] > b[i]) {
        break;
      }
    }
    sum = sum + (c[i] - b[i]) * count;
    cout << sum;
    cout << endl;
  }
  return 0;
}
