human
Can you provide a Python program to determine from which square the robot should start its movement in order to execute as many commands as possible given the following:
PYTHON solution for "The robot is located on a checkered rectangular board of size n × m (n rows, m columns). The rows in the board are numbered from 1 to n from top to bottom, and the columns — from 1 to m from left to right.

The robot is able to move from the current cell to one of the four cells adjacent by side.

Each cell has one of the symbols 'L', 'R', 'D' or 'U' written on it, indicating the direction in which the robot will move when it gets in that cell — left, right, down or up, respectively.

The robot can start its movement in any cell. He then moves to the adjacent square in the direction indicated on the current square in one move. 

  * If the robot moves beyond the edge of the board, it falls and breaks. 
  * If the robot appears in the cell it already visited before, it breaks (it stops and doesn't move anymore). 


Robot can choose any cell as the starting cell. Its goal is to make the maximum number of steps before it breaks or stops.

Determine from which square the robot should start its movement in order to execute as many commands as possible. A command is considered successfully completed if the robot has moved from the square on which that command was written (it does not matter whether to another square or beyond the edge of the board).

Input

The first line contains an integer t (1 ≤ t ≤ 10000) — the number of test cases in the test.

Each test case's description is preceded by a blank line. Next is a line that contains integers n and m (1 ≤ n ≤ 2000.
1 ≤ m ≤ 2000) — the height and width of the board. This line followed by n lines, the i-th of which describes the i-th line of the board. Each of them is exactly m letters long and consists of symbols 'L', 'R', 'D' and 'U'.

It is guaranteed that the sum of sizes of all boards in the input does not exceed 4⋅10^6.

Output

For each test case, output three integers r, c and d (1 ≤ r ≤ n.
1 ≤ c ≤ m.
d ≥ 0), which denote that the robot should start moving from cell (r, c) to make the maximum number of moves d. If there are several answers, output any of...":
assistant
#Here is Python program to determine from which square the robot should start its movement in order to execute as many commands as possible.
 def flood_fill(R, C, graph, r, c):
    d = 0
    nr, nc = r, c
    x = C*nr+nc
    path = {x:1}
    loop = visited = False
    while True:
        if graph[x] >= 1:  # visited
            d = (len(path)-1)+graph[x]
            visited = True
            break
        dr, dc = DIRS[graph[x]]
        nr, nc = divmod(x, C)
        nr, nc = nr+dr, nc+dc
        if not (0 <= nr < R and 0 <= nc < C):  # outside
            break
        x = C*nr+nc
        if x in path:  # loop
            d = len(path)
            for y in path:
                graph[y] = d
                if loop or y == x:
                    loop = True
                    continue
                d -= 1
            break
        path[x] = 1
    if not loop:
        if not visited:
            d = len(path)
        for y in path:
            graph[y] = d
            d -= 1
    return graph[C*r+c]

def solution():
    _ = raw_input()
    R, C = map(int, raw_input().strip().split())
    graph = []
    for _ in xrange(R):
        graph.extend(map((lambda x: TRAN[x]), list(raw_input().strip())))
    x = -1
    for r in xrange(R):
        for c in xrange(C):
            flood_fill(R, C, graph, r, c)
            y = C*r+c
            if x == -1 or graph[y] > graph[x]:
                x = y
    i, j = divmod(x, C)
    return "%s %s %s" % (i+1, j+1, graph[x])

TRAN = {'U':0, 'D':-1, 'L':-2, 'R':-3}
DIRS = {0:(-1, 0), -1:(1, 0), -2:(0, -1), -3:(0, 1)}
for case in xrange(input()):
    print '%s' % solution()