n = int(input())
num_list = list(map(int,input().split()))
q = int(input())
str_list = []
for i in range(q):
    str_list.append(list(map(int,input().split())))

count = 0
for i in range(q):
    SUM = 0
    for j in range(len(str_list)):
        for k in range(len(num_list)):
            if str_list[j][0] == num_list[k]:
                num_list[k] = str_list[j][1]
        SUM = sum(num_list)
        print(SUM)
        count+=1
        if(count == q): break
    if(count == q): break

