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