N = int(input())
A_list = list(map(int,input().split()))
Q = int(input())
S =sum(A_list)
for i in range(Q):
    B,C = map(int,input().split())
    count = 0
    for j in A_list:
        if j == B:
            A_list[A_list.index(j)] = C
            count += 1
    S = S + count * (C - B)
    print(S)