#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
  ll n, sum = 0, q;
  cin >> n;
  ll freq[100001] = {0};
  for (int i = 0; i < n; i++) {
    ll x;
    cin >> x;
    freq[x]++;
    sum += x;
  }
  cin >> q;
  while (q--) {
    ll f, z;
    cin >> f >> z;
    freq[z] += freq[f];
    ll k = (max(f, z) - min(f, z));
    sum += k * freq[f];
    freq[f] = 0;
    cout << sum << endl;
  }
  return 0;
}
