N = int(input())
A = list(map(int, input().split()))
Q = int(input())
for i in range(Q):
    b, c = map(int, input().split())
    if b in A:
        for i in range(len(A)):
            if b == A[i]:
                A[i] = c
    print(sum(A))
