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