n = int(input())
A = list(map(int, input().split()))
q = int(input())

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