if __name__=='__main__':
    N = int(input())
    A = input().split(" ")
    A = [int(s) for s in A]
    Q=int(input())
    str_list=[]
    S=[]
    for i in range(Q):
        str_list.append(list(input().split()))

    for j in range(Q):
        if int(str_list[j][0]) in A:
            #A=[s.replace(int(str_list[j][0]),int(str_list[j][1])) for s in A]
            A=[(int(str_list[j][1])) if i == int(str_list[j][0]) else i for i in A]
        print(sum(A))