#include <bits/stdc++.h>
using namespace std;
int n;
multiset<int> a;
int q;
int main() {
  long long int sum;
  int b, c;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int ain;
    cin >> ain;
    a.insert(ain);
  }
  sum = 0;
  for (auto it = a.begin(); it != a.end(); it++) {
    sum += *it;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    int bnum = a.count(b);
    a.erase(b);
    for (int j = 0; j < bnum; j++) a.insert(c);
    sum += (c - b) * bnum;
    printf("%lld\n", sum);
  }
  return 0;
}
