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