n=int(input())
l=list(map(int,input().split()))
q=int(input())

for i in range(q):
    x,y=map(int,input().split())
    if x not in l:
        print(sum(l))
    else:
        lrep=[y if i==x else i for i in l ]
        print(sum(lrep))
        l=lrep