package main
import (
"fmt"
"os"
)
type Point struct {
x, y int
}
func main() {
var n, m int
if _, err := fmt.Scan(&n, &m); err != nil {
return
}
grid := make([]string, n)
var finish Point
for i := 0; i < n; i++ {
fmt.Scan(&grid[i])
for j := 0; j < m; j++ {
if grid[i][j] == 'F' {
finish = Point{i, j}
}
}
}
queue := []Point{{0, 0}}
parent := make([][]Point, n)
for i := range parent {
parent[i] = make([]Point, m)
for j := range parent[i] {
parent[i][j] = Point{-1, -1}
}
}
parent[0][0] = Point{0, 0}
dx := []int{0, 0, 1, -1}
dy := []int{1, -1, 0, 0}
for len(queue) > 0 {
curr := queue[0]
queue = queue[1:]
if curr == finish {
break
}
for k := 0; k < 4; k++ {
nx, ny := curr.x+dx[k], curr.y+dy[k]
if nx >= 0 && nx < n && ny >= 0 && ny < m {
if grid[nx][ny] != '*' && parent[nx][ny].x == -1 {
parent[nx][ny] = curr
queue = append(queue, Point{nx, ny})
}
}
}
}
var path []Point
curr := finish
for curr != (Point{0, 0}) {
path = append(path, curr)
curr = parent[curr.x][curr.y]
}
for i, j := 0, len(path)-1; i < j; i, j = i+1, j-1 {
path[i], path[j] = path[j], path[i]
}
horizMapped := false
vertMapped := false
rChar, lChar := "R", "L"
dChar, uChar := "D", "U"
currX, currY := 1, 1
for _, p := range path {
nextX, nextY := p.x+1, p.y+1
if nextY > currY {
if !horizMapped {
fmt.Println("R")
fmt.Scan(&currX, &currY)
if currX == -1 {
os.Exit(0)
}
if currY == nextY {
horizMapped = true
} else {
rChar, lChar = "L", "R"
horizMapped = true
fmt.Println(rChar)
fmt.Scan(&currX, &currY)
}
} else {
fmt.Println(rChar)
fmt.Scan(&currX, &currY)
}
} else if nextY < currY {
fmt.Println(lChar)
fmt.Scan(&currX, &currY)
} else if nextX > currX {
if !vertMapped {
fmt.Println("D")
fmt.Scan(&currX, &currY)
if currX == -1 {
os.Exit(0)
}
if currX == nextX {
vertMapped = true
} else {
dChar, uChar = "U", "D"
vertMapped = true
fmt.Println(dChar)
fmt.Scan(&currX, &currY)
}
} else {
fmt.Println(dChar)
fmt.Scan(&currX, &currY)
}
} else if nextX < currX {
fmt.Println(uChar)
fmt.Scan(&currX, &currY)
}
if currX == -1 || currY == -1 {
os.Exit(0)
}
if currX == finish.x+1 && currY == finish.y+1 {
return
}
}
}