#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N, 0);
  map<int, int> mp;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    mp[A[i]]++;
    ans += A[i];
  }
  int Q;
  cin >> Q;
  vector<int> B(N);
  vector<int> C(N);
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
    int cont = mp[B[i]];
    mp[C[i]] += mp[B[i]];
    mp[B[i]] = 0;
    ans += (C[i] - B[i]) * cont;
    cout << ans << endl;
  }
}
