#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
void codeforces()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
string convert(int a) {
    string s;
    map<int, char> m;
    for(char c = 'a'; c<'z'; c++) m[c - 'a' + 1] = c;
    m[0] = 'z';
    while( a> 0){
        s+= m[a%26];
        if( a%26 == 0) a = a/26 - 1;
        else a = a/26;
    }
    reverse(s.begin(), s.end());
    return s;
}
int32_t main()
{
    
    // w(t)
    {
        int n; cin>>n;
        // int a[n];
        map<int, int> m;
        int sum = 0;
        for(int i=0; i<n; i++){
            // cin>>a[i];
            int a; cin>>a;
            sum += a;
            m[a]++;
        }
        int q; cin>>q;
        for(int i=0; i<q; i++){
            int b, c;
            cin>>b>>c;
            cout<<sum - m[b]*b + m[b]*c<<endl;
        }
    }
    return 0;
}