#include <bits/stdc++.h>
using namespace std;
long long gcd(long long n, long long m) { return m ? gcd(m, n % m) : n; }
long long lcm(long long n, long long m) { return n / gcd(n, m) * m; }
struct debugger {
  static void call(string::iterator it, string::iterator ed) {}
  template <typename T, typename... aT>
  static void call(string::iterator it, string::iterator ed, T a, aT... rest) {
    string b;
    for (; *it != ','; ++it)
      if (*it != ' ') b += *it;
    cout << b << "=" << a << " ";
    call(++it, ed, rest...);
  }
};
int arr[100006];
long long sum = 0;
void solve(int n) {
  int a, b;
  cin >> a >> b;
  sort(arr, arr + n);
  int low = lower_bound(arr, arr + n, a) - arr;
  int up = upper_bound(arr, arr + n, a) - arr;
  for (int i = low; i <= up; i++) {
    if (arr[i] == a) {
      sum -= a;
      arr[i] = b;
      sum += b;
    }
  }
  cout << sum << '\n';
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  int test;
  cin >> test;
  for (int i = 0; i < test; i++) {
    solve(n);
  }
}
