#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long a[n];
  map<long long, long long> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  int q;
  cin >> q;
  long long ans[q];
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    int p = mp[b];
    mp[b] = 0;
    mp[c] += p;
    long long su = 0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
      su += itr->first * itr->second;
    }
    ans[i] = su;
  }
  for (int i = 0; i < q; i++) cout << ans[i] << endl;
}
