N = int(input())
A = list(map(str,input().split()))
A = ','.join(A)
Q = int(input())
lst = []
for _ in range(Q):
    a,b = map(int,input().split())
    lst.append([a,b])

for i in range(Q):
    A = A.replace(str(lst[i][0]),str(lst[i][1]))
    ans =A.split(',')
    ans = list(map(int, A.split(',')))
    print(sum(ans))
    A = str(A)
