N = int(input())
A = list(map(int, input().split()))
Q = int(input())
for _ in range(Q):
    b, c = map(int, input().split())
    for i,v in enumerate(A):
        if v == b:
            A[i] = c
    print(sum(A))