// Arup Guha
// 8/25/2016
// Solution for 2016 UCF Locals Problem: Word Search CS Way - (with Loops)

import java.util.*;

public class search_arup {
	
	// Store all information about search directions in parallel arrays.
	final public static int[] DX = {0,1,0,-1};
	final public static int[] DY = {1,0,-1,0};
	final public static String[] CODES = {"R", "D", "L", "U"};
	
	// Elements of a single problem instance
	public static int r;
	public static int c;
	public static char[][] grid;
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();
		
		// Process each case.
		for (int loop=1; loop<=numCases; loop++) {
			
			// Read in the grid in which we'll search.
			r = stdin.nextInt();
			c = stdin.nextInt();
			grid = new char[r][];
			for (int i=0; i<r; i++)
				grid[i] = stdin.next().toCharArray();
			
			// Case header.	
			System.out.println("Word search puzzle #"+loop+":");
			
			// Process each word to search for.
			int numWords = stdin.nextInt();
			for (int i=0; i<numWords; i++) {
				
				// Read the word and find it.
				String word = stdin.next();
				int locCode = getLoc(word);
				
				// Print out what they want.
				System.out.println(CODES[locCode/(r*c)]+" "+((locCode%(r*c))/c+1)+" "+(locCode%c+1)+" "+word);
			}
			
			// Between cases.
			System.out.println();
		}
	}
	
	// Returns the location of word in the grid. If grid is at location (x,y) with direction d
	// we return rcd + cx + y, encoding all 3 pieces of information in one integer. Otherwise,
	// we return -1.
	public static int getLoc(String word) {
		
		// Try each place the word could be!
		for (int i=0; i<r; i++) {
			for (int j=0; j<c; j++) {
				for (int dir=0; dir<DX.length; dir++) {
					
					// This is ever so slightly slower because I build each word instead of cutting out
					// as soon as there's a mismatch, but for the bounds in the problem, this is good
					// enough.
					String item = buildIt(i,j,dir,word.length());
					if (item.equals(word)) return r*c*dir + i*c + j;
				}
			}
		}
		
		// If we get here, the word isn't in the grid.
		return -1;
	}
	
	// Returns the string of length len formed by starting at (x,y) in the grid moving
	// in the direction dir.
	public static String buildIt(int x, int y, int dir, int len) {
		
		String res = "";
		
		// Build the string by adding the current letter and going to the next. Note the +r, +c
		// so that we avoid modding negatives...
		for (int i=0; i<len; i++) {
			res = res + grid[x][y];
			x = (x + DX[dir]+r)%r;
			y = (y + DY[dir]+c)%c;
		}
		
		return res;
	}
}