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

Q=int(input())
for i in range(Q):
    b, c = map(int, input().split())
    a=[i for i, x in enumerate(A) if x == b]
    for j in a:
        A[j]=c
    print(sum(A))