#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  int v[n];
  unordered_map<int, int> m;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    m[v[i]]++;
    sum += v[i];
  }
  int q;
  cin >> q;
  while (q-- > 0) {
    ll b, c;
    cin >> b >> c;
    sum = sum - b * m[b] + c * m[b];
    cout << sum << endl;
  }
}
