#include <bits/stdc++.h>
using namespace std;
int main() {
  long N;
  cin >> N;
  vector<int> arr(N);
  for (long i = 0; i < N; i++) {
    cin >> arr[i];
  }
  long Q;
  cin >> Q;
  vector<int> B(Q);
  vector<int> C(Q);
  for (int i = 0; i < Q; i++) {
    cin >> B[i];
    cin >> C[i];
    for (int j = 0; j < N; j++) {
      if (arr[j] == B[i]) {
        arr[j] = C[i];
      }
    }
    long total = accumulate(arr.begin(), arr.end(), 0);
    cout << total << endl;
  }
}
