N=int(input())
alist=list(map(int, input().split()))
Q=int(input())
bclist=[]
for i in range(Q):
    bclist.append(list(map(int, input().split())))
def repsum(alist,bc):
    alist.sort()
    for i in range(N):
        if alist[i]==bc[0]:
            alist[i]=bc[1]
        elif alist[i]>bc[0]:
            break
    return alist

for bc in bclist:
    alist=repsum(alist,bc)
    print(sum(alist))
