#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long LINF = 1e18;
const int INF = 1e9;
long long A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
vector<long long> aaa(100100);
int main() {
  cin >> N;
  vector<long long> arr(N);
  for (long long i = 0; i < N; i++) {
    cin >> A;
    aaa[A]++;
    arr.at(i) = A;
  }
  long long sum = accumulate((arr).begin(), (arr).end(), 0);
  cin >> Q;
  for (long long i = 0; i < Q; i++) {
    cin >> B >> C;
    D = (C - B) * aaa[B];
    aaa[C] += aaa[B];
    aaa[B] = 0;
    sum += D;
    cout << sum << endl;
  }
  return 0;
}
