#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  static int A[100000];
  static int B[100000];
  static int C[100000];
  static long long S[100000];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
    for (int j = 0; j < N; j++) {
      if (B[i] == A[j]) {
        A[j] = C[i];
      }
    }
    long long sum = 0;
    for (int j = 0; j < N; j++) {
      sum += (long long)A[j];
    }
    printf("%lld", sum);
  }
  return 0;
}
