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())
    BC=[list(map(int,input().split())) for _ in range(Q)]
    for bc in BC:
        cnt=l[bc[0]-1]//bc[0]
        l[bc[0]-1]=0
        l[bc[1]-1]+=bc[1]*cnt
        print(sum(l))
    return

if __name__=='__main__':
    main()
