#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long int N, Q;
  int *A;
  int B, C, s = 0;
  int diff;
  int left, right, mid;
  int j;
  cin >> N;
  A = new int[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    s += A[i];
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    sort(A, A + N);
    cin >> B >> C;
    diff = C - B;
    left = -1;
    right = N;
    while (abs(right - left) > 1) {
      mid = (right + left) / 2;
      if (A[mid] == B) {
        j = 1;
        while (mid + j < N) {
          if (A[mid + j] != B) break;
          A[mid + j] = C;
          s += diff;
          j++;
        }
        j = 1;
        while (mid - j >= 0) {
          if (A[mid - j] != B) break;
          A[mid - j] = C;
          s += diff;
          j++;
        }
        A[mid] = C;
        s += diff;
      } else if (A[mid] < B)
        left = mid;
      else if (A[mid] > B)
        right = mid;
    }
    cout << s << '\n';
  }
  delete[] A;
}
