#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  int64_t res = 0;
  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    res += a;
    mp[a]++;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int from, to;
    cin >> from >> to;
    res -= from * mp[from];
    res += to * mp[from];
    mp[to] += mp[from];
    mp[from] = 0;
    cout << res << '\n';
  }
  return 0;
}
