fork download
  1.  
  2. for i in range(int(input())):
  3. row,col=map(int,input().split())
  4. done=0
  5. lst=[]
  6. for i in range(row):
  7. lst.append([x.lower() for y in input() for x in y])
  8.  
  9. # print(lst[0:6])
  10. # #For rows
  11. if col>=5: #columns should >=5 since spoon has 5 as length
  12. for j in lst:
  13. for i in range(col-4): #shift each letter to rotate and check 5 letter at time
  14. if j[0+i:6+i]==list("spoon"):
  15. done=1
  16. break
  17. #for col
  18. if row>=5:
  19. for j in range(col):
  20. for i in range(row-4):
  21. spoon=""
  22. for k in range(5):
  23. spoon+=lst[k+i][j]
  24.  
  25. if spoon=="spoon":
  26. done=1
  27. break
  28.  
  29. print("There is a spoon!" if done else "There is indeed no spoon!")
  30.  
Success #stdin #stdout 0.04s 9620KB
stdin
1
7 7
abcdefg
acspoon
soklolj
pkeldjf
oeudjvn
ofjdddd
nmkjhfd
stdout
There is a spoon!