#include <bits/stdc++.h>
using namespace std;
const long long MAX = 100005;
int main(void) {
  long long N;
  cin >> N;
  vector<long long> bucket(N);
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    long long tmp;
    cin >> tmp;
    sum += tmp;
    bucket[tmp]++;
  }
  long long Q;
  cin >> Q;
  long long B, C;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    long long diff = C - B;
    sum += bucket[B] * diff;
    bucket[C] += bucket[B];
    bucket[B] = 0;
    cout << sum << "\n";
  }
}
