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