#include <bits/stdc++.h>
using namespace std;
int MAX_N = 100000;
vector<int> count_array(MAX_N, 0);
int main() {
  int N, Q;
  cin >> N;
  vector<int> A(N, 0);
  int s = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    count_array[A[i]] += 1;
    s += A[i];
  }
  cin >> Q;
  vector<int> B(Q, 0);
  vector<int> C(Q, 0);
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
    int tmp = count_array[B[i]];
    s += (C[i] - B[i]) * tmp;
    count_array[C[i]] += tmp;
    cout << s << endl;
  }
}
