#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  int ans = 0;
  map<int, long long> M;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    ans += A[i];
    if (!M.count(A[i]))
      M[A[i]] = 1;
    else
      M[A[i]]++;
  }
  int Q;
  cin >> Q;
  vector<int> B(Q), C(Q);
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
    if (M[B[i]] != 0) ans = ans + M[B[i]] * (C[i] - B[i]);
    M[C[i]] += M[B[i]], M[B[i]] = 0;
    cout << ans << endl;
  }
  return 0;
}
