/*
 * FileName:     D
 * CreatedDate:  2020-06-21 22:09:15 +0900
 * LastModified: 2020-06-21 22:12:47 +0900
 */

#include <stdio.h>
#include <stdlib.h>

int main(void){
    int n;scanf("%d",&n);
    int *a = malloc(n*sizeof(int));
    for(int i=0;i<n;i++)scanf("%d",a+i);
    int q;scanf("%d",&q);
    for(int i=0;i<q;i++){
        int b,c;scanf("%d%d",&b,&c);
        int total=0;
        for(int j=0;j<n;j++){
            if(a[j]==b){
                a[j]=c;
            }
            total+=a[j];
        }
        printf("%d\n",total);
    }
    free(a);
    return 0;
}
