n = int(input())
split = input().split()
inputList = [int(i) for i in split]
q = int(input())
bcList = []
for i in range(q):
    split = input().split()
    tmpList = [int(j) for j in split]
    bcList.append(tmpList)

#n=4
#inputList = [1,2,3,4]
#q=3
#bcList = [[1,2], [3,4], [2,4]]
for i in bcList:
    while i[0] in inputList:
        index = inputList.index(i[0])
        inputList[index] = i[1]
    print(sum(inputList))