#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
const int INF = 1e9 + 23;
const long long INFL = 2e18 + 23;
const int MAX = 1e5 + 2;
int cnt[MAX];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long sum = 0;
  int n;
  cin >> n;
  for (int i = 0, x; i < n; i++) {
    cin >> x;
    cnt[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    cnt[c] += cnt[b];
    sum -= cnt[b] * b;
    sum += cnt[b] * c;
    cout << sum << "\n";
  }
  return 0;
}
