N = int(input())
A_list = list(map(int,input().split()))
Q = int(input())
for i in range(Q):
    B,C = map(int,input().split())
    for j in A_list:
        if j == B:
            A_list[A_list.index(j)] = C
    print(sum(A_list))