#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void) {
  int n;
  cin >> n;
  vector<ll> ans;
  map<int, int> mp;
  ll tmp = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    mp[a]++;
    tmp += a;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int before, after;
    cin >> before >> after;
    tmp += after * mp[before];
    tmp -= before * mp[before];
    mp[after] += mp[before];
    mp[before] = 0;
    ans.push_back(tmp);
  }
  for (int i = 0; i < q; i++) cout << ans[i] << endl;
  return 0;
}
