题目描述
Problem Description
In the debris of a废弃宇宙飞船, there is a robot. Somewhere in the debris, there is a teleportation device that can send this poor robot to a safe place.
The宇宙飞船is uncontrollably tumbling in all directions. Light from a nearby star can illuminate the debris. The飞船is equipped with an artificial gravity generator. The artificial gravity always pulls the robot away from the star, regardless of the飞船's orientation.
The robot is equipped with solar panels and must rely on solar energy to move on the debris. When a part of the debris blocks the light, the robot cannot move. However, the robot always secures itself after moving to avoid being shaken off or falling into space.
The debris and the surrounding area can be represented by a three-dimensional coordinate space of size $m \times n \times p$. Each small grid in the space can be either part of the debris or vacuum. The飞船debris may not be connected.
The robot is initially secured on one of the pieces of the飞船. The robot can decide when to move or when to wait for the light to come from the right direction.
Formally, gravity can act on the robot in six directions, including two directions along each of the three coordinate axes. A grid has light if there is no debris blocking the opposite direction of gravity. Both the starting and ending grids must have light when moving.
The following are the available movement methods: (light shines from above the depicted space; blue grid represents the robot; orange grid represents a possible movement destination)
- Moving on Flat Ground
If the robot is secured on a piece, it can move to an adjacent piece at the same height.
The robot cannot move diagonally. The destination must also have light.

- Jumping Down from a Height
The robot can step out from a height and then fall. There is no limit to the falling height.
The robot cannot fall into space or land in a place without light.

- Falling
If the robot has light and is suspended in the air, it can fall. This situation may occur after the direction of gravity changes.
The robot cannot fall into space.

The robot's goal is to reach the location of the teleportation device, using the fewest number of moves if there are multiple ways. The teleportation device requires the robot to be secured on the飞船. In other words, the robot must arrive at the teleportation device's location after a move, but passing over it while falling does not activate it. The teleportation device does not block light or hinder the robot's movement.
Input Format
The first line contains three integers $m, n, p \ (1 \leq m, n, p \leq 500)$.
The飞船and the surrounding space are described as $p$ blocks.
The $k$-th block describes the grids at height $k$. Each block contains $n$ lines.
The $i$-th line of the $k$-th block contains $m$ characters, describing the state of that grid. Let $a_{ijk}$ represent the $j$-th character.
- If $a_{ijk}$ is
*, this grid is debris. - If $a_{ijk}$ is
-, this grid is vacuum. - If $a_{ijk}$ is
R, this grid is the robot. The data guarantees that there is only one grid with the robot, and the robot is secured on a debris grid. - If $a_{ijk}$ is
T, this grid is the teleportation device. The data guarantees that there is only one grid with the teleportation device.
Output Format
Output the minimum number of moves required to reach the teleportation device. If there is no solution, output $-1$.
Sample Input and Output
Sample Input #1
2 5 1
R-
*-
*-
*T
**
Sample Output #1
1
Sample Input #2
3 2 1
R-T
***
Sample Output #2
2
Sample Input #3
3 3 1
-R-
-*-
-T-
Sample Output #3
-1
Sample Input #4
5 4 2
-R---
-****
-****
-****
-----
-----
*T---
----*
Sample Output #4
5
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分