See the problem statement here: [http://codeforces.com/contest/921/problem/01](//codeforces.com/contest/921/problem/01).
none
none
import argparse
import sys

from collections import deque, namedtuple

def read_int():
	return int(input())

def read_str():
	return input()

def read_list(t=int):
	return list(map(t, raw_input().split()))

def print_list(x):
	print(len(x), ' '.join(map(str, x)))

# ----------------------------------------

inf = 1e18
dirs = [
	(-1, 0, 'move-up'),
	(1, 0, 'move-down'),
	(0, 1, 'move-right'),
	(0, -1, 'move-left'),
]

def ok(pos):
	gy, gx = pos
	return (gx >= 0 and gx < m and
					gy >= 0 and gy < n)

def step_cost(start, goal, through_walls, through_doors):
	sy, sx = start
	gy, gx = goal
	if not ok(start) or not ok(goal):
		return inf
	if (sy, sx, gy, gx) in walls:
		return through_walls
	if (sy, sx, gy, gx) in doors:
		return through_doors
	return 1

Move = namedtuple('Move', ['y', 'x', 'desc', 'dist'])

def empty_move():
	return Move(y=-1, x=-1, desc='', dist=-1)

def list_moves(starts, goal, prevs):
	moves = []
	_c = goal
	while _c not in starts:
		moves.append(prevs[_c])
		_c = (prevs[_c].y, prevs[_c].x)
	return list(reversed(moves))

def bfs(starts, goal, through_walls=inf, through_doors=inf):
	assert goal is None or goal not	in starts, 'bfs: goal in starts'
	q = deque([Move(y=s[0], x=s[1], desc='', dist=0) for s in starts])
	moves = []
	prevs = {}
	reached = False
	while len(q):
		cur = q.popleft()
		if (cur.y, cur.x) == goal:
			return (list_moves(starts, goal, prevs), prevs)
		for dir in dirs:
			dy, dx, desc = dir
			ny, nx = cur.y + dy, cur.x + dx
			cost = step_cost((cur.y, cur.x), (ny, nx), through_walls, through_doors)
			if (
					(ny, nx) not in prevs # TODO: or prevs[(ny, nx)].dist > cur.dist+cost
				 ) and cost < inf:
				prevs[(ny, nx)] = Move(y=cur.y, x=cur.x, desc=desc, dist=cur.dist+cost)
				q.append(Move(y=ny, x=nx, desc=desc, dist=cur.dist+cost))
	return ([], prevs)


# -------------------------------------------------------------------

class Robot(object):
	"""docstring for Robot"""
	def __init__(self, y, x):
		super(Robot, self).__init__()
		self.pos = y,x
		self.keys = 0
		
	def go(self, goal, real=True):
		moves, _ = bfs([self.pos], goal)
		if real and moves:
			self.pos = goal
		return moves

	def find_and_go(self, goals, max_dist=inf):
		dists = self.distances(goals)
		if dists:
			dist, goal = dists[0]
			if dist <= max_dist:
				return self.go(goal)
		return []

	def distances(self, goals):
		_, prevs = bfs([self.pos], None)
		dists = []
		for goal in goals:
			if goal in prevs:
				dists.append((prevs[goal].dist + self.place_costs[goal], goal))
		# print(dists)
		return sorted(dists)

	def cost(self, goal):
		if goal in self.place_costs:
			return self.place_costs[goal]
		return inf

	def preprocess(self):
		_, prevs = bfs(exits, None, through_doors=5, through_walls=10000)
		self.place_costs = dict([
			(cell, move.dist) for cell, move in prevs.items()
		])
		# print(self.place_costs)

# ----------------------------------------

def s1():
	cmds = []
	robot = Robot(sy, sx)
	robot.preprocess()
	max_dist = 20
	while robot.pos not in exits:
		moves = robot.find_and_go(exits, max_dist)
		if not moves:
			if robot.keys:
				moves = robot.find_and_go(doors)
				if moves:
					moves.append(Move(y=robot.pos[0], x=robot.pos[1], desc='open-up', dist=0))
					moves.append(Move(y=robot.pos[0], x=robot.pos[1], desc='open-down', dist=0))
					moves.append(Move(y=robot.pos[0], x=robot.pos[1], desc='open-left', dist=0))
					moves.append(Move(y=robot.pos[0], x=robot.pos[1], desc='open-right', dist=0))
				else:
					#raise Exception("Doors cannot be found!")
					max_dist *= 1.5
			else:
				moves = robot.find_and_go(keys)
				if moves:
					# raise Exception("Key cannot be found!")
					moves.append(Move(y=robot.pos[0], x=robot.pos[1], desc='take', dist=0))
					robot.keys += 1
				else:
					max_dist *= 1.5
		if moves:
			cmds.extend(moves)
	return cmds

def compress(cmds):
	cmds.append(empty_move())
	compressed_cmds = []
	current = None
	counter = 0
	for i, cmd in enumerate(cmds):
		if not current or current.desc != cmd.desc:
			if current:
				compressed_cmds.append((current, counter))
			current = cmd
			counter = 0
		counter += 1
	for cmd, counter in compressed_cmds:
		if counter == 0:
			assert False
		elif counter == 1:
			print(cmd.desc)
		else:
			print("for-%d" % counter)
			print(cmd.desc)
			print("end")


# ----------------------------------------

parser = argparse.ArgumentParser()
parser.add_argument('--strategy', default='s1', type=str, required=False)
args = parser.parse_args()

_, _, n, m, sx, sy, num_walls, num_doors, num_keys, num_exits = read_list()
walls = set()
for _ in range(num_walls):
	_a, _b, _c, _d = read_list()
	walls.add((_a, _b, _c, _d))
	walls.add((_c, _d, _a, _b))

doors = set()
for _ in range(num_doors):
	_a, _b, _c, _d = read_list()
	doors.add((_a, _b, _c, _d))
	doors.add((_c, _d, _a, _b))

keys = set()
for _ in range(num_keys):
	_x, _y = read_list()
	keys.add((_x, _y))

exits = set()
for _ in range(num_exits):
	_x, _y = read_list()
	exits.add((_x, _y))

compress(eval(args.strategy)())