#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  long long arr[n];
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    mp[arr[i]] += 1;
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) ans += arr[i];
  long long t;
  cin >> t;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    long long x = mp[a];
    ans -= a * x;
    ans += x * b;
    mp[b] += x;
    cout << ans << "\n";
  }
  return 0;
}
