
n = int(input())
a_list = list(map(int, input().split()))
q = int(input())

for id in range(q):
    query = list(map(int, input().split()))
    for i in range(n):
        if int(a_list[i]) == int(query[0]) :
            a_list[i] = int(query[1])

    print(sum(a_list))