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

for i in range(Q):
    l = list(map(int, input().split()))
    for j in range(N):
        if A[j] == l[0]:
            A[j] = l[1]
    S = sum(A)
    print(S)