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