#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  unordered_map<int, int> mp;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int c;
    cin >> c;
    sum = sum + c;
    mp[c]++;
  }
  int q;
  cin >> q;
  unordered_map<int, int>::iterator itr, it;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    itr = mp.find(b);
    if (itr != mp.end()) {
      if (mp[b] > 0) {
        sum = sum - itr->second * (itr->first - c);
        mp[c] = mp[c] + itr->second;
        mp[b] = 0;
      }
    }
    cout << sum << endl;
  }
}
