#input the number of A and an array of A
#then from the number of input Q input number on B and C array
#using while loop to replaces number that same in A and B with C in A
#print the total sum of A on each operation

A=[]
B=[]
C=[]
N=int(input()) #O(1)
A=list(map(int,input().split())) #O(n)
Q=int(input()) #O(1)

x=0
while x<Q:
    b,c=map(int,input().split()) #O(n)
    B.append(b) #O(1)
    C.append(c) #O(1)
    x+=1

x=0  
y=0
while x<Q:
    while y<N:
        if A[y]!=B[x]: #O(1)
            y+=1
            continue
        else:
            A[y]=C[x] #O(1)
            continue

    z=0
    total=0
    while z<N:
        total=total+A[z] #O(1)
        z+=1
        
    print(total) #O(1)
    y=0
    x+=1
