N = int(input())
A = [int(a) for a in input().split()]
Q = int(input())
ch = [[int(c) for c in input().split()] for _ in range(Q)]
for s in ch:
    for i in range(len(A)):
        if A[i]==s[0]:A[i]=s[1]
    print(sum(A))