#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long N, Q;
  cin >> N;
  vector<long long> A(N);
  for (long long i = 0; i < long long(N); i++) cin >> A[i];
  cin >> Q;
  vector<long long> B(Q);
  vector<long long> C(Q);
  for (long long i = 0; i < long long(Q); i++) cin >> B[i] >> C[i];
  vector<long long> kosu(2 + 10e+5, 0);
  for (long long i = 0; i < long long(N); i++) {
    kosu[A[i]]++;
  }
  long long sum = accumulate(A.begin(), A.end(), 0);
  for (long long i = 0; i < long long(Q); i++) {
    long long diff = C[i] - B[i];
    sum += diff * kosu[B[i]];
    cout << sum << endl;
    kosu[C[i]] += kosu[B[i]];
    kosu[B[i]] = 0;
  }
  return 0;
}
