#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; ++i) cin >> A[i];
  int Q;
  cin >> Q;
  int BC[Q][2];
  for (int i = 0; i < Q; ++i) cin >> BC[i][0] >> BC[i][1];
  for (int i = 0; i < Q; i++) {
    long res = 0;
    for (int j = 0; j < N; j++) {
      if (A[j] == BC[i][0]) {
        res += BC[i][1];
        A[j] = BC[i][1];
      } else {
        res += A[j];
      }
    }
    cout << res << endl;
  }
}
