#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  int a[n];
  map<int, int> mp;
  set<int> s;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
    s.insert(a[i]);
  }
  int q;
  cin >> q;
  while (q--) {
    int bi, ci;
    cin >> bi >> ci;
    mp[ci] += mp[bi];
    auto it = s.find(bi);
    s.erase(it);
    mp[bi] = 0;
    int sum = 0;
    for (auto it : s) {
      sum += (it * mp[it]);
    }
    cout << sum << endl;
  }
}
