#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q, a[100009], b, c;
  cin >> N;
  for (int i = 0; i < N; i++) cin >> a[i];
  sort(a, a + N);
  long long int s[100009];
  s[0] = 0;
  for (int i = 0; i < N; i++) s[0] += a[i];
  cin >> Q;
  for (int i = 1; i <= Q; i++) {
    cin >> b >> c;
    s[i] = s[i - 1];
    int dif = c - b;
    int j = lower_bound(a, a + N, b) - a;
    while (a[j] == b) {
      a[j] = c;
      s[i] += dif;
      j++;
    }
    sort(a, a + N);
  }
  for (int i = 1; i <= Q; i++) cout << s[i] << endl;
  return 0;
}
