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

s = []
for i in range(Q):
    BC = list(map(int, input().split()))
    for j in range(len(A)):
        if (A[j] == BC[0]):
            A[j] = BC[1]
    s.append(sum(A))

for i in range(Q):
    print(s[i])