#include <bits/stdc++.h>
using namespace std;
long long factorial(long long n) {
  return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
int max3(int a, int b, int c) { return max(a, max(c, b)); }
int gcd(int a, int b) {
  if (a == 0) {
    return b;
  } else {
    return gcd(b % a, a);
  }
}
long long power(long long a, long long n) {
  if (n == 1)
    return a;
  else if (n == 0)
    return 1;
  else {
    long long r = power(a, n / 2);
    if (n % 2 == 0)
      return r * r;
    else
      return r * a * r;
  }
}
long long nCr(long long n, long long r) {
  return ((factorial(n)) / (factorial(n - r) * factorial(r)));
}
void dfs(vector<vector<int> >& v, vector<int>& check, int start) {
  check[start - 1] = 1;
  for (long long j = 0; j < v[start - 1].size(); j++) {
    if (!check[v[start - 1][j] - 1]) {
      dfs(v, check, v[start - 1][j]);
    }
  }
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> rec;
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    rec.push_back(num);
  }
  sort(rec.begin(), rec.end());
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    int p1 = lower_bound(rec.begin(), rec.end(), b) - rec.begin();
    int p2 = upper_bound(rec.begin(), rec.end(), b) - rec.begin();
    replace(rec.begin() + p1, rec.begin() + p2, b, c);
    sort(rec.begin(), rec.end());
    long long sum = accumulate(rec.begin(), rec.end(), 0);
    cout << sum << "\n";
  }
}
