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