#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll arr[100001];
int main() {
  ll n;
  cin >> n;
  ll sum = 0;
  for (ll i = 0; i < n; ++i) {
    ll tmp;
    cin >> tmp;
    arr[tmp]++;
    sum += tmp;
  }
  ll q;
  cin >> q;
  while (q--) {
    ll a, b;
    cin >> a >> b;
    arr[b] += arr[a];
    sum += (b - a) * arr[a];
    cout << sum << endl;
  }
  return 0;
}
