#include <bits/stdc++.h>
using namespace std;
int main() {
  long long counter[100001];
  for (int i = 0; i < 100001; i++) counter[i] = 0;
  long long N;
  cin >> N;
  long long A[N];
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    ans += A[i];
    counter[A[i]]++;
  }
  long long Q;
  cin >> Q;
  long long B[Q];
  long long C[Q];
  long long Ans[Q];
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
    Ans[i] = (C[i] - B[i]) * counter[B[i]] + ans;
  }
  for (int i = 0; i < Q; i++) {
    cout << Ans[i] << endl;
  }
  return 0;
}
