#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define xrep(i,a,b) for(int i=int(a);i<int(b);++i)
using ll = long long;

int main() {
    ll N;
    vector<int> A;
    int Q;
    vector<vector<int>> BC;
    cin >> N;
    rep(i, N) {
        int a;
        cin >> a;
        A.push_back(a);
    }
    cin >> Q;
    rep(i, Q) {
        int b, c;
        cin >> b >> c;
        BC.push_back({b, c});
    }

    sort(A.begin(), A.end());

    rep(q, Q) {
        // rep(n, N) {
        //     if(A[n] == BC[q][0]) {
        //         A[n] = BC[q][1];
        //     }
        // }
        int left = 0;
        int right = A.size()-1;
        while(right>=left) {
            int mid = left + (right-left)/2;
            if(A[mid] == BC[q][0]) A[mid] = BC[q][1];
            else if (A[mid] > BC[q][0]) right = mid-1;
            else if (A[mid] < BC[q][0]) left = mid+1;
        }
        
        int sum = 0;
        rep(n, N) {
            sum += A[n];
        }
        cout << sum << endl;
    }
