#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int32_t main() {
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  long long arr[n];
  map<long long, long long> mp;
  long long jml = 0;
  for (long long i = 0; i < (long long)n; ++i) {
    cin >> arr[i];
    if (mp.count(arr[i]) == 0) {
      mp[arr[i]] = 1;
    } else
      mp[arr[i]]++;
    jml += arr[i];
  }
  long long q;
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    if (mp.count(b) == 0) {
      continue;
    }
    jml = jml + c * (mp[b]) - b * mp[b];
    if (mp.count(c) == 0)
      mp[c] = mp[b];
    else
      mp[c] = mp[c] + mp[b];
    mp[b] = 0;
    cout << jml << '\n';
  }
  return 0;
}
