#include <bits/stdc++.h>

using namespace std;

int main(){
    int N;
    cin >> N;
    int A[N] = {};

    int x;
    for (int n = 0; n < N; n++)
    {
        cin >> x;
        A[n] = x;
    }
    int Q;
    cin >> Q;
    int B, C;
    for (int q; q < Q; q++)
    {
        cin >> B >> C;
        long long s = 0;
        if(q==0){
            for (int n = 0; n < N; n++)
            {
                if(A[n]==B){
                    A[n] = C;
                }
                s += A[n];
            }
            cout << s << "\n";
        }
        else
        {
            for (int n = 0; n < N; n++){
                if(A[n]==B){
                    A[n] = C;
                    s += C - B;
                }
            }
            cout << s << "\n";
        }
    }
}
