#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
int main(void) {
  int N;
  cin >> N;
  map<int, int> mp;
  ll sum = 0;
  for (int i = (0); i < (N); ++i) {
    int A;
    cin >> A;
    mp[A]++;
    sum += A;
  }
  int Q;
  cin >> Q;
  vector<ll> ans(Q);
  for (int i = (0); i < (Q); ++i) {
    int B, C;
    cin >> B >> C;
    int cnt = mp[B];
    sum -= cnt * B;
    sum += cnt * C;
    mp[B] = 0;
    mp[C] += cnt;
    ans[i] = sum;
  }
  for (int i = (0); i < (Q); ++i) cout << ans[i] << endl;
  return 0;
}
