T=int(input()) def rep_mul(a,x,m): t=0 val=a while t40: X = find_min_2x(L-30) A=[rep_mul(A[i],X,m)+rep_mul(A[i+X],X,m) for i in range(L-X)] L-=X print(process(A,m)) for _ in range(T): solve()