C=10**7+1
G=lambda:(s*5402147+54321)%C
import sys
I=map(int,sys.stdin.read().split())[1:]
while I:
n=I[0]+1;S=range(C)
for x in I[1:n]:S=[G()for s in S if s%1000==x]
if len(S)-1:V="Not enough observations"if S else"Wrong machine"
else:
s=S[0];V=""
for i in range(10):V+="%d "%(s%1000);s=G()
print V;I=I[n:]
Try it online!
import sys
n=1e7+1
for s in[map(int,x.split())for x in sys.stdin][1:]:
Q=[]
for i in range(s[1],n,1e3):A=[i];R=[A.append((A[-1]*5402147+54321)%n)or A[-1]%1e3for x in[0]*8+s];Q+=[R[-10:]]*(R[:-10]==s[2:])
print Q and["%d "*10%tuple(Q[0]),"Not enough observations"][len(Q)>1]or"Wrong Machine"
Try it online!