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