#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  ll ts = 0;
  for (int i = 0; i < n; ++i) {
    int ele;
    cin >> ele;
    ts += ele;
    mp[ele]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    ll ans = ts - (mp[b] * b);
    ans += mp[b] * c;
    cout << ans << "\n";
    int temp = mp[b];
    mp[c] += temp;
    ts = ts - (mp[b] * b);
    ts = ts + (mp[b] * c);
    mp[b] = 0;
  }
}
