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