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

for i in range(Q):
    l = list(map(int, input().split()))
    # S = 0
    # for j in range(N):
    #     if A[j] == l[0]:
    #         A[j] = l[1]
        # S += A[j]
    S = sum([l[1] if A[j] == l[0] else A[j] for j in range(N)])
    print(S)