#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  ll A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  int Q;
  cin >> Q;
  ll B[Q], C[Q];
  map<ll, ll> mp;
  for (int i = 0; i < Q; i++) cin >> B[i] >> C[i];
  for (int i = 0; i < N; i++) {
    mp[A[i]]++;
  }
  for (int i = 0; i < Q; i++) {
    mp[C[i]] += mp[B[i]];
    mp[B[i]] = 0;
    ll res = 0;
    for (auto x : mp) {
      res += x.first * x.second;
    }
    cout << res << endl;
  }
  return 0;
}
