N = int(input())
A =[]
for i in (input().split()):
    A.append(int(i))
Q = int(input())

for i in range(Q):
    B, C = map(int, input().split())

    for i, j in enumerate(A):
        if j == B:
            A[i] = C
    print(sum(A))