\problemname{A-Mazing Puzzle}

The Severely Challenging Archaeological Exploration Division (SCArED) specializes in the investigation of archaeological sites that are too difficult, dangerous or downright terrifying for humans to examine firsthand.  Instead they send in one or more mobile robots to investigate, each robot outfitted with a complex set of sensors, recorders and manipulators.  Each robot is radio-controlled and has a small nuclear reactor to power what sometimes ends up being an extended stay at the sites.

Recently a complex underground maze of the Desreverezam Civilization has been discovered.  SCArED sent in two robots to investigate and over the course of several months they have mapped out the entire maze.  But then disaster struck~---~due to some unforeseen anomaly they no longer have radio contact with the two robots (the researchers are torn between the cause of this: either some magnetoferritin crystals in the walls or angry poltergeists).  After several weeks of trying to regain contact with the two robots they finally have managed to open up a shared channel with them.  There's not much bandwidth in the connection, so they can only send three basic commands to the robots: (Move) Forward, (Turn) Left and (Turn) Right.  Since this is a shared channel they cannot send differentiated commands to each robot, so if they send the Forward command each robot will try to move forward simultaneously.  If there is an opening in front of them that's fine but if there's a wall in front of one of the robots it will bump into the wall and remain where it is.   Any Turn command will likewise cause the robots to turn in lockstep.

\begin{figure}[!h]
\centering
\includegraphics[width=0.45\textwidth]{maze}
\caption{Sample Input $1$.}
\label{fig:maze}
\end{figure}

The researchers would like to find the minimum number of Forward commands to get both robots out of the maze (the Turn commands take so little time and power that they can be ignored).  As soon as either is out of the maze they can return to the surface and ignore any future commands.  Consider the situation in Figure \ref{fig:maze} where both robots are currently facing South. One approach to get the robots out of the maze is to first get robot B out as quickly as possible by moving it to locations $(6,2)$, $(6,1)$, $(5,1)$, $(4,1)$ and then out of the maze.  This takes $5$ Forward moves and in the process robot A moves to $(3,1)$ and stays there, bumping against walls $4$ times.  After robot B is out robot A can exit  the maze in $6$ more Forward moves, for a total of $11$ moves.  However, if robot A is moved out as quickly as possible first and then robot B is moved out, only $8$ Forward moves are needed.  For other mazes, the minimum number of Forward moves may not involve getting either robot out as quickly as possible (see Sample Input~2).

Given a maze and the initial positions and orientations of the robots, help the researchers out by determining the minimum number of Forward commands to get both robots out of the maze.  If there are several sets of minimum Forward commands then the one that leads to the least number of wall bumps is preferred.  Oh, and one more thing: the robots should never be on top of each other inside the maze~---~this may lead to a chain reaction of their nuclear power generators leading to an explosion that could destroy the planet.  This should be avoided.

\section*{Input}
Input starts with a line containing $3$ positive integers $c$ $r$ $e$ $(c,r \leq 50, e \leq c)$  indicating the maze has $c$ columns and $r$ rows (all numbered starting at $1$) and that the exit to the maze is on the southern side of square $(e,1)$.  Following this is a line of the form $c_1$ $r_1$ $d_1$ $c_2$ $r_2$ $d_2$ ($1 \leq c_i \leq c, 1 \leq r_i \leq r, d_i \in \{\mbox{\tt N,E,S,W}\})$ indicating that the two robots are at locations $(c_1,r_1)$ and $(c_2,r_2)$ with orientations $d_1$ and $d_2$, respectively.  Locations $(c_1, r_1)$ and $(c_2, r_2)$ will never be the same, and $d_1$ and $d_2$ may be different.

After this come two lines which describe the maze.  The first line has the form $n$ $c_1$ $r_1$ $c_2$ $r_2 \ldots c_n$ $r_n$ ($n \leq r*c, 1 \leq c_i \leq c, 1 \leq r_i < r$) where each $c_i$ $r_i$ pair indicates that there is a horizontal wall between grid squares $(c_i,r_i)$ and $(c_i,r_i+1)$.  The next line is similar, where each $c_i$ $r_i$ pair ($n \leq r*c, 1 \leq c_i < c, 1 \leq r_i \leq r$) indicates that there is a vertical wall between grid squares $(c_i,r_i)$ and $(c_i+1,r_i)$.  All exterior walls except the exit are assumed to exist and are not listed in these two lines.

\section*{Output}
Output two values: the minimum number of Forward commands to get the two robots out of the maze and the number of bumps that occur using these commands.  If there are several ways to get the robots out with the same minimum number of Forward command, use the one that minimizes the number of bumps.   It will be possible for both robots to escape the maze in each input instance.

%\section*{Comment}
%The solution I envision is a breadth-first search of a graph with each node representing the joint locations of the robots.  With an n x m matrix there are only nm choose 2 possible nodes so that should guide us to the maximum size maze we can use.  The reason I only want to count the Move Forward command is that otherwise we also have to take into account the orientation of the robots which multiplies the number of nodes by 4.

%Question: Should we include the fact that some optimal solutions don't involve the optimal way to get any robot out individually (i.e., the solution to Sample Input 2) or should we let the contestants figure that out themselves.
