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

for i in range(Q):
    k = 0
    B,C = map(int,input().split())
    change = [n for n, v in enumerate(A) if v == B]
    size = len(change)
    for j in range(size):
        A[change[k]] = C
        k += 1
    print(sum(A))
