N = int(input())
A = list(map(int, input().split()))
Q = int(input())
bc = [map(int, input().split()) for _ in range(Q)]
B, C = [list(i) for i in zip(*bc)]



for i in range(Q):
    
    a = [j for j, x in enumerate(A) if x == B[i]]
    for k in range(len(a)):
        A[a[k]] = C[i]
    # print(A)
    print(sum(A))