n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int,input().split())) for _ in range(q)]

# sum_first  = sum(a)

for i in bc:
    a = [i[1] if j==i[0] else j for j in a]
    # print(a)
    print(sum(a))