def main():
    N=int(input())
    l=[0]*10**5
    A=map(int, input().split())
    for a in A:
        l[a-1]+=a
    Q=int(input())
    ans=[]
    for _ in range(Q):
        B,C=map(int, input().split())
        cnt=l[B-1]//B
        l[B-1]=0
        l[C-1]+=C*cnt
        ans.append(str(sum(l)))
    print('\n'.join(ans))
    return

if __name__=='__main__':
    main()
