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