#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N, A[int(pow(10, 5)) + 10], i, Q;
  ll B[int(pow(10, 5)) + 10], C[int(pow(10, 5)) + 10];
  ll sum = 0;
  ll plus = 0;
  ll num[int(pow(10, 5)) + 10];
  cin >> N;
  for (i = 0; i < (N); i++) cin >> A[i];
  cin >> Q;
  for (i = 0; i < (Q); i++) cin >> B[i] >> C[i];
  for (i = 0; i < (N); i++) sum += A[i];
  for (int j = 0; j < N; j++) {
    num[A[j]]++;
  }
  for (int j = 0; j < Q; j++) {
    plus = (C[j] - B[j]) * num[B[j]];
    cout << sum + plus << endl;
    sum += plus;
    num[C[j]] += num[B[j]];
    num[B[j]] = 0;
  }
  return 0;
}
