F - GPS  

The Problem

You have to write a program that provides navigation instructions for going from one place to another based on a map.

The program will receive a map and the coordinates of the origin and destination points, and should provide turn by turn instructions for reaching from the origin to the destination following the shortest path.

The Input

The input format is as follows:

An integer in a single line which says the number of problems to solve. Then, for each problem:

The Output

The output for each problem consists of a list of step by step instructions to go from the origin to the destination through a shortest path.

In case that there are more than one shortest path, the program should provide the one which, at each step, goes preferably east, then south, then west and finally north. That is, given two shortest routes, the most preferable one is that which, once it arrives to the first different step, goes east if possible, otherwise goes south if possible, otherwise goes west if possible and otherwise goes north.

If there is no way to go from the origin to the destination using the roads of the map, then the program should print "No route found.".

To describe a route, the program should print one instruction per line:

The program must use as few instructions as possible to describe the route. Also, it should print a blank line after each solution (so, and the end of the input there are two new line characters).

Sample Input

2
10 8
+----------+
| |
| ***** |
| * * |
| *** * |
| * |
| *** |
| * |
| * |
+----------+
1 3 7 7
15 15
+---------------+
|*** |
| * |
| * |
| * |
| ******** |
| **** |
| ***** |
| **** |
| **** |
| * |
| *** |
| * * |
| *** |
| * |
| ******|
+---------------+
0 0 14 14

Sample Output

Turn to the east.
Continue 2 km.
Turn left.
Continue 2 km.
Turn right.
Continue 4 km.
Turn right.
Continue 6 km.
You have reached your destination.

Turn to the east.
Continue 2 km.
Turn right.
Continue 4 km.
Turn left.
Continue 7 km.
Turn right.
Continue 4 km.
Turn left.
Continue 2 km.
Turn right.
Continue 2 km.
Turn left.
Continue 1 km.
Turn right.
Continue 2 km.
Turn right.
Continue 1 km.
Turn left.
Continue 2 km.
Turn left.
Continue 3 km.
You have reached your destination.


OMP'14
Facultad de Informática
Universidad de Murcia