n = int(input())
A = list(map(int,input().split()))
q = int(input())
ansList = [0]*q

for i in range(q):
    b,c = map(int,input().split())
    for j in range(n):
        if A[j] == b:
            A[j] = c
    ansList[i]  = sum(A)


[print(ans) for ans in ansList]