#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, q, a[N], mp[N];
long long ans;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i], mp[a[i]] += a[i], ans += a[i];
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    mp[y] += mp[x] / x * y;
    ans -= mp[x];
    ans += mp[x] / x * y;
    mp[x] = 0;
    cout << ans << "\n";
  }
  return 0;
}
