n = int(input())
A = list(map(int, input().split()))
q = int(input())
B = []
C = []
D = []
for i in range(q):
    ans = 0
    b, c = map(int, input().split())
    for j in range(len(A)):
        if A[j] == b:
            A[j] = c
            ans += c
        else:
            ans += A[j]
    print(ans)
