#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  map<int, int> mp;
  int x;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    mp[x]++;
    sum += x;
  }
  int q;
  int a, b;
  cin >> q;
  while (q--) {
    cin >> a >> b;
    int cnt = mp[a];
    sum -= (cnt * a);
    mp.erase(mp.find(a));
    if (mp.find(b) != mp.end()) {
      mp[b] += cnt;
    } else {
      mp.insert({b, cnt});
    }
    sum += (cnt * b);
    cout << sum << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
