n = int(input())
a = list(map(int, input().split()))

q = int(input())
int_list = [list(map(int, input().split())) for _ in range(q)]
sum = 0
for i in range(q):
    if int_list[i][0] in a:
        while int_list[i][0] in a:
            index = a.index(int_list[i][0])
            a[index] = int_list[i][1]
        for j in a:
                sum += j

        print(sum)
        sum = 0