#include <bits/stdc++.h>
using namespace std;
bool T = false;
int main() {
  long long N, Q;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  cin >> Q;
  vector<pair<long long, long long>> B(Q);
  for (int i = 0; i < Q; i++) {
    cin >> B[i].first >> B[i].second;
  }
  sort(B.begin(), B.end());
  sort(A.begin(), A.end());
  long long sum = 0;
  for (int i = 0; i < Q; i++) {
    for (int j = 0; j < N; j++) {
      if (A[j] == B[i].first) A[j] = B[i].second;
      sum += A[j];
    }
    cout << sum << endl;
    sum = 0;
  }
}
