#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
const long long inf = 1000000001; // const 書き換え禁止

int main(void){
    int n;
    cin >> n;
    int a[n];
    int sum0 = 0;
    rep(i,n){
        cin >> a[i];
        sum0 += a[i];
    }
    int q;
    cin >> q;
    int sum1[q];
    int m = 0;
    int count[q] = {0};
    int count2[q] = {1};
    rep(i,q){
        int sum = 0;
        int b,c;
        cin >> b >> c;
        rep(j,n){
            if(a[j] == b){
                a[j] = c;
                count[i] += c-b;
                //count2[i]++;
            }
        }
        // rep(k,n){
        //     sum += a[k];
        // }
        // sum1[m] = sum;
        // m++;
    }
    rep(i,q){
        cout << sum0 + count[i] << endl;
        sum0+=count[i];
    }
    // rep(i,q){
    //     cout << sum1[i] << endl;
    // }
}