#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int sum = 0;
  unordered_map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    sum += x;
    mp[x]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int bi, ci;
    cin >> bi >> ci;
    auto it = mp.find(bi);
    if (it != mp.end()) {
      int z = ci - it->first;
      sum += (z * it->second);
      int dd = it->second;
      mp.erase(it);
      if (mp.find(ci) != mp.end()) {
        mp[ci] = mp[ci] + dd;
      } else
        mp[ci] = dd;
      cout << sum << endl;
    } else
      cout << sum << endl;
  }
}
