n=int(input())
initial=list(map(int,input().split(" ")))
q=int(input())
for _ in range(q):
    x,y=map(int,input().split(" "))
    for i in range(len(initial)):
        if initial[i]==x:
            initial[i]=y
        else:
            continue
    print(sum(initial))