#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long N, Q;
  cin >> N;
  map<long long, long long> A;
  for (long long i = 0; i < N; i++) {
    long long j;
    cin >> j;
    A[j]++;
  }
  cin >> Q;
  for (long long i = 0; i < Q; i++) {
    long long B, C;
    cin >> B >> C;
    A[C] += A[B];
    A.erase(B);
    long long k = 0;
    for (pair<long long, long long> j : A) k += j.first * j.second;
    cout << k << endl;
  }
}
