#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
const ll INF = 1e18;
inline void chmax(ll& a, ll b) { a = max(a, b); }
inline void chmin(ll& a, ll b) { a = min(a, b); }
ll cnt[100005];
int main() {
  ll n;
  cin >> n;
  vector<ll> A(n);
  ll sum = 0;
  for (ll i = 0; i < (100005); ++i) cnt[i] = 0;
  for (ll i = 0; i < (n); ++i) {
    cin >> A[i];
    cnt[A[i]]++;
    sum += A[i];
  }
  ll q;
  cin >> q;
  for (ll i = 0; i < (q); ++i) {
    ll a, b;
    cin >> a >> b;
    ll kosuu = cnt[a];
    ll ans = sum + kosuu * (b - a);
    cout << ans << endl;
  }
  return 0;
}
