n = int(input())
list_in = list(map(int, input().split()))
q = int(input())
for i in range(q+1):
    bc = list(map(int, input().split()))
    for j in range(n):
        if list_in[j] == bc[0]:
            list_in[j] = bc[1]
    print(sum(list_in))
