_,*t=open(0) for s in t: h,w=len(t),len(s)-1 if'R'in s:p,q=t.index(s),s.index('R') while(s:=t[p:=-~p%h][q:=-~q%w])=='.':() print(f'{p%-h+h} {q%-w+w}'if s<'R'else'loop')