I – Jungle of Coconuts


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

توضیح تصویر

Once upon a time Mohammadreza and Mehrdad (M&M) decided to go to jungle to bring as many coconuts as possible. But unfortunately “Mehrzad the Kaftar” (his friends call him “Lion”) was following them. M&M are smart so they realised Lion was following them. When they just realised it, Mohammadreza climbed a tree and said to Mehrdad “Ble Ble Ble”!!!. Mehrdad couldn’t understand what Mohammadreza was saying and he was unable to climb trees so he ran. Mehrdad is good with geography so he knows jungle very well. He knows that there are some fences that only Lion can pass through (Lion jumps over it and takes 2 seconds) and some other fences that no one can pass (not Lion nor Mehrdad). There are also some Tunnels that Lion can not reach, so if Mehrdad gets there, he’s safe. Mehrdad is frightened so he can’t think, the only thing he can do is run. Mehrdad and lion move one cell at a time (1 second) and they can only move in four directions: up, down, left, right. Can you help him?

ورودی🔗

First line of the input contains an integer T(T20)T (T ≤ 20) indicating number of test cases to follow. The first line of each test case will be given two integers NN and M(1N,M500)M (1 ≤ N,M ≤ 500), the height and width of the jungle. Each of the following NN lines contain MM characters, describing the jungle. if JJ’th character of ii’th line is ‘.’ it’s free cell, if it’s ‘M’ Mehrdad is there, if it’s ‘L’ Lion is there, if it’s ’O’ there is a tunnel there, if it’s ‘#’ there’s a long fence there and if it’s ‘+’ there’s a small fence there. If Mehrdad and Lion reach at same cell in a same time, Mehrdad will be eaten by Lion.

It’s guaranteed there are no more than 10 tunnels, and Mehrdad can always reach at least one tunnel (but he may be eaten in the way).

خروجی🔗

For each test case output a line containing “Case XX: ” (quotations for clarify) which XX is number of the test case. If Mehrdad can’t survive print “goodgood byebye mymy deardear goodgood friendfriend :(:(” (quotations for clarify). If Mehrdad can survive print the position of top left most (first TopTop, Then LeftLeft) tunnel he can reach.

مثال‌ها🔗

ورودی نمونه ۱🔗

2
1 12
O.+.M..L..O.
1 12
O...M..L..O.
Plain text

خروجی نمونه ۱🔗

Case 1: good bye my dear good friend :(
Case 2: 1 1
Plain text