#include <bits/stdc++.h>
using namespace std;

int binary_search(int v[], int x, int N) {
    int stanga = 0, dreapta = N - 1, m;
    while (stanga < dreapta) {
        m = (stanga + dreapta) / 2;
    if (v[m] < x)
        stanga = m + 1;
    else
        dreapta = m;
    }
    if (v[stanga] == x)
        return stanga;
    return -1;
}
int main () {
    int n, k, v[10000];
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> v[i];
    sort(v, v + n);
    cin >> k;
    for(int i = 0; i < k; i++) {
        int s = 0, bi, ci;
        cin >> bi >> ci;
        if(binary_search(v, bi, n) != -1)
            int j = binary_search(v, bi, n);
            while(v[j] == bi) {
                v[j] = ci;
                j++
            }
        for(int j = 0; j < n; j++)
            s += v[j];
        cout << s << '\n';
    }
}
