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