fork download
  1. # your code goes here
  2. t=int(input())
  3. for c in range(t):
  4. s=input()
  5. hr=ord(s[0])-ord('0')
  6. hrs=ord(s[1])-ord('0')
  7. hh=hr*10+hrs
  8. time=""
  9. if hh<12:
  10. time="AM"
  11. else:
  12. time="PM"
  13. hh%=12
  14. if(hh==0):
  15. print(12,end="")
  16. for i in range(2,len(s)):
  17. print(s[i],end="")
  18.  
  19. else:
  20. if(hh<10):
  21. print(f'0{hh}',end="")
  22. else:
  23. print(hh,end="")
  24. for i in range(2,len(s)):
  25. print(s[i],end="")
  26. print(" "+time)
  27.  
Success #stdin #stdout 0.03s 9944KB
stdin
11
09:41
18:06
12:14
00:59
00:00
14:34
01:01
19:07
11:59
12:00
21:37
stdout
09:41 AM
06:06 PM
12:14 PM
12:59 AM
12:00 AM
02:34 PM
01:01 AM
07:07 PM
11:59 AM
12:00 PM
09:37 PM