#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  long long n, q;
  long long sum = 0;
  cin >> n;
  int a[n];
  for (long long i = 0; i < (long long)(n); i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a, a + n);
  long long count = 1;
  long long cons = a[0];
  map<int, int> mp;
  for (long long i = 1; i < (long long)(n); i++) {
    if (a[i] == a[i - 1]) {
      count++;
    } else {
      mp[cons] = count;
      count = 1;
      cons = a[i];
    }
  }
  mp[cons] = count;
  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    std::cout << "key = " << itr->first << ", val = " << itr->second << "\n";
  }
  cin >> q;
  int b, c;
  for (long long i = 0; i < (long long)(q); i++) {
    cin >> b >> c;
    auto itr = mp.find(b);
    if (itr != mp.end()) {
      count = mp[b];
      mp[b] = 0;
      auto itr = mp.find(c);
      if (itr != mp.end()) {
        mp[c] += count;
      } else {
        mp[c] = count;
      }
      sum += (c - b) * count;
    }
    cout << (int)sum << endl;
  }
  return 0;
}
