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

        if int(str_list[0]) not in banlist:
            if int(str_list[0]) in A:
                #A=[s.replace(int(str_list[j][0]),int(str_list[j][1])) for s in A]
                A=[(int(str_list[1])) if i == int(str_list[0]) else i for i in A]
            else:
                banlist.append(int(str_list[0]))

        print(sum(A))