Maze#4966

Maze

0.5 seconds
64 megabytes
Medium

One of the most popular games of all times is the "Maze". The game is played on a N \times M table. The player can make the instructions: 'left', 'right', 'up', 'down'. For each cell of the table and each instruction the game-master has defined the destination cell that the player moves to; that is, the player is given the map of the maze. Once a game was interrupted, and the master has forgotten which cell the player was in. Fortunately, a full record of the gameplay has remained, which is the sequence of the instructions made by the player.

You are to write a program determining the cells that the player can be currently in.

Input

The first line of the input contains two numbers and (1 \le N, M \le 100). Four blocks of lines each follow. Each line contains pairs, being the new coordinates of the player after making 'th instruction standing in the cell , where is the number of pair in the line, is the number of line in the block, and is the number of block. Following is the number (1 \le S \le 4000) of the instructions made by the player. The last line contains the numbers of the instructions made.

Output

The first line of the output must contain the number of the cells that player can be in after making the given sequence of instructions. Each of the next lines must contain the coordinates of these cells, ordered first by the first coordinate, and then by the second.

Examples

Example 1

Loading
Loading