#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ull = unsigned long long;
char toSmall(char c) { return (c + 0x20); }
char toLarge(char c) { return (c - 0x20); }
float myPower(int a, int n) {
  float x = 1;
  while (n > 0) {
    if (n & 1) {
      x *= a;
    }
    a *= a;
    n >>= 1;
  }
  return x;
}
ll combination(ll n, ll r) {
  if (n < 0 || r < 0 || r > n) return -1;
  if (n - r < r) r = n - r;
  if (r == 0) return 1;
  if (r == 1) return n;
  vector<ll> num(r);
  vector<ll> den(r);
  for (ll i = 0; i < r; i++) {
    num[i] = n - r + i + 1;
    den[i] = i + 1;
  }
  for (ll p = 2; p <= r; p++) {
    ll pivot = den[p - 1];
    if (pivot > 1) {
      ll offset = (n - r) % p;
      for (ll k = p - 1; k < r; k += p) {
        num[k - offset] /= pivot;
        den[k] /= pivot;
      }
    }
  }
  ll result = 1;
  for (ll k = 0; k < r; k++) {
    if (num[k] > 1) result *= num[k];
  }
  return result;
}
vector<string> split(const string& src, const char* delim = ",") {
  vector<string> vec;
  string::size_type len = src.length();
  for (string::size_type i = 0, n; i < len; i = n + 1) {
    n = src.find_first_of(delim, i);
    if (n == string::npos) {
      n = len;
    }
    vec.push_back(src.substr(i, n - i));
  }
  return vec;
}
bool check_int(string str) {
  if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch); })) {
    return true;
  }
  return false;
}
struct rest {
  string s;
  int p;
  int num;
  bool operator<(const rest& right) const {
    return s == right.s ? p > right.p : s < right.s;
  }
};
int binary_search(int key, vector<ll> a) {
  int left = 0, right = (int)a.size() - 1;
  while (right >= left) {
    int mid = left + (right - left) / 2;
    if (a[mid] == key)
      return mid;
    else if (a[mid] > key)
      right = mid - 1;
    else if (a[mid] < key)
      left = mid + 1;
  }
  return -1;
}
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  ll q;
  cin >> q;
  for (ll i = 0; i < q; i++) {
    ll b, c;
    cin >> b >> c;
    while (true) {
      int index = binary_search(b, a);
      if (index != -1) {
        a[index] = c;
        sort(a.begin(), a.end());
      } else {
        break;
      }
    }
    ll ans = 0;
    for (int j = 0; j < n; j++) {
      ans += a[j];
    }
    cout << ans << endl;
  }
  return 0;
}
