#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);
    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];
    }
    vector<int> sum(q);
    int basesum=0;
    rep(i,n){
        basesum+=a[i];
    }
    rep(i,n){
        rep(j,q){
            if(a[i]==b[j]){
                a[i]=c[j];
                sum[j]+=c[j]-b[j];
            }
        }
    }
    rep(i,q){
        count<<basesum+sum[j]<<endl;
    }
}