#include<stdio.h>

int main(){
    int N;
    scanf("%d", &N);
    int A[N];
    for (int i=1; i<=N; ++i){
        scanf("%d", &A[N]);
    }
    int Q;
    scanf("%d",&Q);
    for (int i=1; i<Q; ++i){
        int B,C,sum=0;
        scanf("%d%d",&B,&C);
        for (int j=0; j<N; ++j){
            if(A[j]==B) A[j]=C;
            sum+=A[j];
        }
        printf(sum);
    }
}