#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000;
int N, Q, B[MAX_N], C[MAX_N];
vector<int> A;
int main() {
  scanf("%d", &N);
  int tmp;
  for (int i = 0; i < N; i++) {
    scanf("%d", &tmp);
    A.push_back(tmp);
  }
  scanf("%d", &Q);
  for (int i = 0; i < Q; i++) scanf("%d %d", &B[i], &C[i]);
  sort(A.begin(), A.end());
  int n = 0;
  while (Q--) {
    int b = B[n], c = C[n];
    vector<int>::iterator it = lower_bound(A.begin(), A.end(), b);
    while (*it == b) {
      *it = c;
      it++;
    }
    cout << accumulate(A.begin(), A.end(), 0) << endl;
    n++;
  }
  return 0;
}
