{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"problem_par\"\u003e\u003cdiv class\u003d\"problem_par_normal\"\u003eOne of the most popular games of all times is the \"Maze\". The game is played on a \u003ci\u003eN\u003c/i\u003e × \u003ci\u003eM\u003c/i\u003e table. The player can make the instructions: \u0027left\u0027, \u0027right\u0027, \u0027up\u0027, \u0027down\u0027. 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\r\ngameplay has remained, which is the sequence of the instructions made by the player. You are to write a program determining the cells that\r\nthe player can be currently in.\u003c/div\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cdiv class\u003d\"problem_par\"\u003e\u003cdiv class\u003d\"problem_par_normal\"\u003eThe first line of the input contains two numbers \u003ci\u003eN\u003c/i\u003e and \u003ci\u003eM\u003c/i\u003e (1 ≤ \u003ci\u003eN\u003c/i\u003e,\u003ci\u003eM\u003c/i\u003e ≤ 100). Four blocks of \u003ci\u003eN\u003c/i\u003e lines each follow. Each line contains \u003ci\u003eM\u003c/i\u003e pairs, being the new coordinates of the player after making \u003ci\u003ek\u003c/i\u003e\u0027th instruction standing in the cell (\u003ci\u003ej\u003c/i\u003e, \u003ci\u003ei\u003c/i\u003e), where \u003ci\u003ei\u003c/i\u003e is the number of pair in the line, \u003ci\u003ej\u003c/i\u003e is the number of line in the block, and \u003ci\u003ek\u003c/i\u003e is the number of block.\r\nFollowing is the number \u003ci\u003eS\u003c/i\u003e (1 ≤ \u003ci\u003eS\u003c/i\u003e ≤ 4000) of the instructions made by the player. The last line contains the \u003ci\u003eS\u003c/i\u003e numbers of the instructions made.\u003c/div\u003e\u003c/div\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cdiv class\u003d\"problem_par\"\u003e\u003cdiv class\u003d\"problem_par_normal\"\u003eThe first line of the output must contain the number \u003ci\u003eL\u003c/i\u003e of the cells that player can be in after making the given sequence of instructions. Each of the next \u003ci\u003eL\u003c/i\u003e lines must contain the coordinates of these cells, ordered first by the first coordinate, and then by the second.\u003c/div\u003e\u003c/div\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e2 3\r\n1 2 1 3 1 3\r\n2 2 2 3 2 3\r\n2 1 2 2 2 3\r\n2 1 2 2 2 3\r\n1 1 1 1 1 2\r\n2 1 2 1 2 2\r\n1 1 1 2 1 3\r\n1 1 1 2 1 3\r\n4\r\n1 2 3 4\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\r\n1 1\r\n1 2\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}