#include <bits/stdc++.h>
using namespace std;
using in = int64_t;
const double PI = 3.14159265358979323846;
const in MOD = 1000000007;
const in INF = 1e18 + 7;
const int inf = 1e9 + 7;
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (int)(n); i++) cin >> a.at(i);
  int q;
  cin >> q;
  vector<int> b(q), c(q);
  for (int i = 0; i < (int)(q); i++) cin >> b.at(i) >> c.at(i);
  vector<int> d(100500);
  sort(a.begin(), a.end());
  in s = 0;
  for (int i = 0; i < (int)(n); i++) s += a.at(i);
  for (int i = 0; i < (int)(q); i++) {
    auto itr1 = lower_bound(a.begin(), a.end(), b.at(i));
    auto itr2 = upper_bound(a.begin(), a.end(), b.at(i));
    int g = distance(itr1, itr2);
    d.at(c.at(i)) += d.at(b.at(i)) + g;
    s += (c.at(i) - b.at(i)) * (d.at(b.at(i)) + g);
    d.at(b.at(i)) = 0;
    cout << s << endl;
  }
}
