#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using Byte = unsigned char;
using namespace std;
void SetAns() {
  ll N;
  vector<int> A(200000, 0);
  cin >> N;
  int tmp;
  for (int i = 0; i < N; i++) {
    cin >> tmp;
    A[tmp]++;
  }
  int Q;
  int B, C;
  cin >> Q;
  for (int _i = 0; _i < Q; _i++) {
    cin >> B >> C;
    A[C] += A[B];
    A[B] = 0;
    ll nowAns = 0;
    for (int i = 0; i < 100000; i++) nowAns += (ll)A[i + 1] * (ll)(i + 1);
    cout << nowAns << endl;
  }
  return;
}
int main() {
  SetAns();
  return 0;
}
