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