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