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