#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using Graph = vector<vector<int>>;
using ll = long long;


int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    int sum=0;
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    int q;
    cin>>q;
    vector<int> b(q);
    vector<int> c(q);
    rep(i,q){
        cin>>b[i]>>c[i];
    }
    sort(a.begin(),a.ebd());
    vector<int> what(1,a[0]);
    vector<int> kosu(1,0);
    int temp=a[0];
    rep2(i,1,n){
        if(temp==a[i]){
            kosu.end()++;
        }
        else{
            temp=a[i];
            what.push_back(a[i]);
            kosu.push_back(0);
        }
    }
    rep(i,q){
        rep(j,what.size()){
            if(b[i]==what[j]){
                sum+=kosu[j]*(c[i]-b[i]);
            }
        }
        cout<<sum<<endl;
    }
}