#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long N;
  cin >> N;
  vector<unsigned long long> av;
  unsigned long long sum = 0u;
  for (unsigned long long i = 0; i < N; ++i) {
    unsigned long long a;
    cin >> a;
    av.emplace_back(a);
    sum += a;
  }
  unsigned long long Q;
  cin >> Q;
  vector<unsigned long long> bv;
  vector<unsigned long long> cv;
  for (unsigned long long i = 0; i < Q; ++i) {
    unsigned long long b;
    cin >> b;
    bv.emplace_back(b);
    unsigned long long c;
    cin >> c;
    cv.emplace_back(c);
  }
  sort(av.begin(), av.end());
  unsigned long long currentSum = sum;
  for (unsigned long long i = 0; i < Q; ++i) {
    unsigned long long j = 0u;
    unsigned long long changedCount = 0u;
    bool isFound = false;
    while (j < N && !isFound) {
      if (av[j] == bv[i]) {
        while ((j < N) && (av[j] == bv[i])) {
          av[j] = cv[i];
          ++j;
          ++changedCount;
          isFound = true;
        }
        break;
      } else {
        ++j;
      }
    }
    currentSum += (changedCount * (cv[i] - bv[i]));
    cout << currentSum << endl;
    sort(av.begin(), av.end());
  }
}
