fromcollectionsimportdequeforTinrange(int(input())):command=deque(input().split())N=command.popleft()B=deque()O=deque()order=deque()whilecommand:i=command.popleft()ifi=="B":B.append(int(command.popleft()))order.append("B")else:O.append(int(command.popleft()))order.append("O")count=0b,o=1,1whileTrue:ifnotorder:breakcount+=1BP="안눌림"ifB:ifB[0]>b:b+=1elifB[0]==bandorder[0]=="B":B.popleft()order.popleft()BP="눌림"elifB[0]<b:b-=1ifO:ifO[0]>o:o+=1elifO[0]==oandorder[0]=="O"andBP=="안눌림":O.popleft()order.popleft()elifO[0]<o:o-=1print(f'#{T+1}{count}')# 주어진 순서대로 버튼을 눌러야 한다!!!# 첫번째 테스트의 경우 O에 1이 있으나, B2가 눌리기를 기다려야 한다.# order 리스트가 필요한 이유
P=[2]foriinrange(3,3162,2):forqinP:ifi%q==0:breakelse:P.append(i)ans=[]forTinrange(int(input())):N=int(input())result,n=1,NforvinP:count=0ifn==1orv>N:breakwhilen%v==0:n//=vcount+=1ifcount%2!=0:result*=vifn>1:result*=nans.append(f'#{T+1}{result}')foriinans:print(i)# 에라토스테네스 체를 이용해 소수를 구했고# root(10000001**0.5) 보다 큰 소수의 경우 # 소인수 분해를 하고 나서도 n != 1 수 있다.# 하여 소인수분해를 마치고도 n > 1면 # result에 곱해주었다.# 속도와 n이 root보다 큰 경우가 있다는 것을 깨닫는데# 오랜시간이 걸렸던 문제.