#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  map<long long, long long> mp;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    sum += x;
    mp[x]++;
  }
  long long q;
  cin >> q;
  while (q--) {
    long long x, y;
    cin >> x >> y;
    long long k = mp[x];
    mp[y] += k;
    sum += k * (y - x);
    cout << sum << '\n';
  }
  return 0;
}
