#include <bits/stdc++.h>
using namespace std;
int n, q, bi, ci;
vector<int> bit, arr;
map<int, pair<int, int>> segments;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  arr.resize(n);
  for (int &x : arr) cin >> x;
  sort(arr.begin(), arr.end());
  for (int i = 0; i < n; i++) {
    int j = i;
    while (j < n && arr[i] == arr[j]) j++;
    segments[arr[i]] = {i, j - 1};
    i = j - 1;
  }
  long long tot = accumulate(arr.begin(), arr.end(), 0);
  cin >> q;
  while (q--) {
    cin >> bi >> ci;
    if (segments.count(bi)) {
      auto range = segments[bi];
      int qtd = (range.second - range.first + 1);
      tot -= (long long)bi * (long long)qtd;
      tot += (long long)ci * (long long)qtd;
      segments.erase(bi);
      if (segments.count(ci)) {
        auto range2 = segments[ci];
        range = {min(range.first, range2.first),
                 max(range.second, range2.second)};
      }
      segments[ci] = range;
      cout << tot << endl;
    } else {
      cout << tot << endl;
    }
  }
}
