for _ in range(int(input())): m=int(input()) D=list(map(int, input().split())) tmp="" for i,d in enumerate(D,1): if d==0:continue tmp+=str(i)*d tmp=int(tmp)*(10**8) if tmp%m!=0: tmp+=m-tmp%m assert tmp%m==0 assert tmp<=10**18 print(tmp)