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

# Define constants
N, M = 0, 0
walls = set()
doors = set()
keys = set()
exits = set()
visited = set()
commands = []

# Define helper functions
def move(dir):
    commands.append(f"move-{dir}")

def open_door(dir):
    commands.append(f"open-{dir}")

def take_key():
    commands.append("take")

def explore(x, y):
    visited.add((x, y))
    for dir in ["down", "right"]:
        new_x, new_y = x, y
        if dir == "down":
            new_x += 1
        else:
            new_y += 1
        if 0 <= new_x < N and 0 <= new_y < M and (new_x, new_y) not in visited:
            if (x, y, new_x, new_y) in walls:
                continue
            if (x, y, new_x, new_y) in doors and (new_x, new_y) not in keys:
                continue
            move(dir)
            if (x, y, new_x, new_y) in doors and (new_x, new_y) in keys:
                open_door(dir)
            if (new_x, new_y) in keys:
                take_key()
            explore(new_x, new_y)

# Read input
i, W, N, M, x0, y0, C, D, K, E = map(int, input().split())
for _ in range(C):
    x1, y1, x2, y2 = map(int, input().split())
    walls.add((x1, y1, x2, y2))
    walls.add((x2, y2, x1, y1))
for _ in range(D):
    x1, y1, x2, y2 = map(int, input().split())
    doors.add((x1, y1, x2, y2))
    doors.add((x2, y2, x1, y1))
for _ in range(K):
    x, y = map(int, input().split())
    keys.add((x, y))
for _ in range(E):
    x, y = map(int, input().split())
    exits.add((x, y))

# Start exploring from the initial position
explore(x0, y0)

# Print the commands
print(" ".join(commands))

# Terminate the program
print("terminate")