#include <bits/stdc++.h>
using namespace std;
signed main() {
  int N;
  cin >> N;
  vector<int> A(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  unsigned long long int count = 0;
  int Q;
  cin >> Q;
  vector<int> B(Q + 1);
  vector<int> C(Q + 1);
  for (int i = 1; i <= Q; i++) {
    cin >> B[i] >> C[i];
  }
  for (int i = 1; i <= Q; i++) {
    for (int j = 1; j <= N; j++) {
      if (A[j] == B[i]) {
        A[j] = C[i];
      }
      count += A[j];
    }
    cout << count << endl;
    count = 0;
  }
}
