_,a=input(),map(int,input().split())
for _ in range(int(input())):
    org,rplc=input().split()
    org,rplc=int(org),int(rplc)
    
    a=[rplc if n==org else n for n in a]
    sumw=sum(i for i in a)
    print(sumw)
    sumw=0
