#include <bits/stdc++.h>
using namespace std;
long long int tc = 1;
int cnt[100005];
void solve() {
  long long int n, sum = 0;
  cin >> n;
  while (n--) {
    long long int a;
    cin >> a;
    cnt[a]++;
    sum += a;
  }
  long long int q;
  cin >> q;
  while (q--) {
    long long int t, r;
    cin >> t >> r;
    long long int num = cnt[t];
    sum -= (t * num);
    sum += (r * num);
    cnt[r]++;
    cnt[t] = 0;
    cout << sum << endl;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
