#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  map<long long int, long long int> mp;
  for (int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    mp[x]++;
  }
  long long int quary;
  cin >> quary;
  for (int i = 0; i < quary; i++) {
    long long int x, y;
    cin >> x >> y;
    mp[y] = mp[y] + mp[x];
    mp.erase(x);
    long long int ans = 0;
    for (auto it = mp.begin(); it != mp.end(); ++it) {
      ans = ans + ((it->first) * (it->second));
    }
    cout << ans << endl;
  }
}
