N = int(input())
li = list(map(int,input().split()))
Q = int(input())
li2 = list()

for i in range(Q):
    b,c=map(int,input().split())
    for j in range(N):
        if li[j] == b:
            li [j] = c
    li2.append(sum(li))

for i in range(Q):
    print(li2[i])