- import java.util.Scanner;
- import java.io.*;
- public class Bugbunny {
- public static void main(String[] args) throws IOException {
- Scanner in = new Scanner(System.in);
- int a = in.nextInt();
- int a1 = 0;
- while (a1 < a) {
- int elmer = in.nextInt();
- int b = in.nextInt();
- int inbug = in.nextInt();
- String[][] move = new String[b][elmer + 1];
- for (int i = 0; i < b; i++) {
- String c = in.next();
- for (int j = 0; j < c.length(); j++) {
- move[i][j] = c.substring(j, j + 1);
- }
- }
- boolean[][] tree = new boolean[elmer + 1][(int)Math.pow(2,(b + 1))+1];
- tree[0][inbug] = true;
- for (int i = 1; i < elmer + 1; i++) {
- tree[i][1] = true;
- }
- boolean d = false;
- for (int i = 0; i < b; i++) {
- for (int j = 0; j < elmer + 1; j++) {
- if (samebugnode(tree) > 0) {
- System.out.print((i+1) + " " + samebugnode(tree));
- d = true;
- break;
- }
- if (move[i][j].equals("L")) lmove(tree, posbugel(tree, j), j);
- if (move[i][j].equals("R")) rmove(tree, posbugel(tree, j), j);
- if (move[i][j].equals("U")) umove(tree, posbugel(tree, j), j);
- if (samebugnode(tree) > 0) {
- System.out.print((i+1) + " " + samebugnode(tree));
- d = true;
- break;
- }
- }
- if (d) break;
- }
- if(a1<a-1) System.out.println("");
- if(!d)System.out.print("0 0");
- a1++;
- }
- }
- public static void lmove(boolean[][] tree, int pos, int no) {
- tree[no][pos] = false;
- tree[no][pos * 2] = true;
- }
- public static void rmove(boolean[][] tree, int pos, int no) {
- tree[no][pos] = false;
- tree[no][pos * 2 + 1] = true;
- }
- public static void umove(boolean[][] tree, int pos, int no) {
- tree[no][pos] = false;
- tree[no][pos / 2] = true;
- }
- public static int posbugel(boolean[][] tree,int no) {
- for (int i = 0; i < tree[no].length; i++) {
- if (tree[no][i]) return i;
- }
- return 0;
- }
- public static int samebugnode(boolean[][] tree) {
- for (int i = 0; i < tree[0].length; i++) {
- for(int j =1;j<tree.length;j++){
- if (tree[0][i]) if (tree[j][i]) return j;
- }
- }
- return 0;
- }
- }