#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long N;
  cin >> N;
  long long A[N];
  long long ans = 0;
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (long long i = 0; i < N; i++) {
    ans += A[i];
  }
  long long Q;
  cin >> Q;
  long long div = 0;
  long long count = 0;
  long long B[Q], C[Q];
  for (long long j = 0; j < Q; j++) {
    cin >> B[j] >> C[j];
  }
  sort(A, A + N);
  long long count1 = 0;
  for (long long j = 0; j < Q; j++) {
    div = C[j] - B[j];
    count = 0;
    count1 = 0;
    sort(A, A + N);
    for (long long i = 0; i < N; i++) {
      if (A[i] < B[j]) {
        break;
      }
      if (A[i] == B[j]) {
        A[i] = C[j];
        count++;
      }
      count1++;
    }
    ans += count * div;
    cout << ans << endl;
  }
}
