#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long arr[N];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  map<long long, long long> mp;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    mp[arr[i]]++;
    sum += arr[i];
  }
  long long b, c, q;
  cin >> q;
  while (q--) {
    cin >> b >> c;
    long long bb = mp[b];
    long long cc = mp[c];
    sum += (cc * c - bb * b);
    cout << sum << "\n";
    mp[c] += mp[b];
    mp[b] = 0;
  }
  return 0;
}
