#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char *argv[]) {
  int N;
  cin >> N;
  int *A = new int[N];
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  int Q;
  cin >> Q;
  unsigned long int *S = new unsigned long int[Q];
  for (int qi = 0; qi < Q; ++qi) {
    int B, C;
    cin >> B >> C;
    S[qi] = 0;
    for (int ni = 0; ni < N; ++ni) {
      if (A[ni] == B) {
        A[ni] = C;
      }
      S[qi] += A[ni];
    }
  }
  for (int i = 0; i < Q; ++i) {
    cout << S[i] << endl;
  }
  return 0;
}
