N = int(input())

A = list(map(int,input().split()))

Q = int(input())

sumlist = []

for i in range(Q):
    B, C = map(int, input().split())
    for j in range(len(A)):
        if A[j] == B:
            A[j] = C
    sumlist.append(sum(A))

for k in range(len(sumlist)):
    print(sumlist[k])