#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int INF = 1001001001;
int main() {
  long long N, Q, ans = 0;
  cin >> N;
  vector<int> A(N), a(100001, 0);
  for (int i = 0; i < (N); ++i) {
    cin >> A[i];
    a[A[i]]++;
    ans += A[i];
  }
  cin >> Q;
  vector<int> B(Q), C(Q);
  for (int i = 0; i < (Q); ++i) {
    cin >> B[i] >> C[i];
    ans -= B[i] * a[B[i]];
    ans += C[i] * a[B[i]];
    a[C[i]] += a[B[i]];
    a[B[i]] = 0;
    cout << ans << endl;
  }
  return 0;
}
