#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
ll mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  cin >> n;
  vector<int> A(n);
  map<int, int> mp;
  for (int i = 0; i < (int)n; i++) {
    cin >> A[i];
    mp[A[i]]++;
  }
  cin >> q;
  vector<int> B(q), C(q);
  for (int i = 0; i < (int)q; i++) cin >> B[i] >> C[i];
  ll ans = 0;
  for (int i = 0; i < (int)n; i++) {
    ans += A[i];
  }
  for (int i = 0; i < (int)q; i++) {
    if (mp[B[i]] == 0) continue;
    ans += (C[i] - B[i]) * mp[B[i]];
    mp[C[i]] += mp[B[i]];
    mp[B[i]] = 0;
    cout << ans << endl;
  }
  return 0;
}
