#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 B[Q];
  int C[Q];
  for (int j = 0; j < Q; j++) cin >> B[j] >> C[j];
  for (int j = 0; j < Q; j++) {
    int sum = 0;
    for (int i = 0; i < N; i++) {
      if (A[i] == B[j]) A[i] = C[j];
      sum += A[i];
    }
    cout << sum << endl;
  }
  return 0;
}
