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