#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100001];
long long int fxp(long long int a, long long int b) {
  if (b == 0) return 1;
  if (b % 2 == 0) {
    long long int c = fxp(a, b / 2);
    return (c * c) % 1000000007;
  }
  return (a * fxp(a, b - 1)) % 1000000007;
}
int lcm(int c, int d) {
  int a = c;
  int b = d;
  int ans;
  if (a >= b) {
    while (b != 0) {
      int x = b;
      b = a % b;
      a = x;
    }
    ans = (c * d) / a;
  } else {
    while (a != 0) {
      int x = a;
      a = b % a;
      b = x;
    }
    ans = (c * d) / b;
  }
  return ans;
}
int root_find() {
  long long int x;
  for (int i = 1; i < 100001; i++) {
    if (adj[i].size() == 1) {
      x = i;
      break;
    }
  }
  return x;
}
void dfs(int s, int y) {
  for (int i = 0; i < adj[s].size(); i++) {
    if (adj[s][i] == y) continue;
    dfs(adj[s][i], s);
  }
}
bool isPrime(long long int 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;
}
long long int smallestDivisor(long long int n) {
  if (n % 2 == 0) return n / 2;
  for (int i = 3; i * i <= n; i += 2) {
    if (n % i == 0) return n / i;
  }
  return n;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int n;
  cin >> n;
  long long int a[n];
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum = sum + a[i];
  }
  sort(a, a + n);
  long long int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long int b, c;
    cin >> b >> c;
    while (binary_search(a, a + n, b)) {
      long long int k = lower_bound(a, a + n, b) - a;
      a[k] = c;
      sort(a, a + n);
      sum = sum + (c - b);
    }
    cout << sum << '\n';
  }
  return 0;
}
