See the problem statement here: [http://codeforces.com/contest/921/problem/01](//codeforces.com/contest/921/problem/01).
none
none
#include <bits/stdc++.h>
using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define mp make_pair
#define pb push_back
#define fs first
#define sc second

int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string name[4] = {"right", "down", "left", "up"};
bool wall[1010][1010][4];
int n, m;
pair<int, int> p[1010][1010];
int len[1010][1010];

bool ok(int x, int y) {
    return 0 <= x && x < n && 0 <= y && y < m;
}

bool ex[1010][1010];

int jpeg(vector<string> &S) {
    map<string, int> M;
    vector<string> I;
    vector<int> a;
    cerr << endl;
    for (auto s: S) {
        int x = 0;
        if (M.find(s) == M.end()) {
            x = I.size();
            M[s] = x;
            I.pb(s);
        } else {
            x = M[s];
        }
        a.pb(x);
        cerr << x << " ";
    }
    cerr << endl;
    int isz = I.size();
    for (int l = 2; l <= a.size() / 2 && l < 3000; ++l) {
        forn (i, a.size() + 1 - 2 * l) {
            int cnt_for = 0;
            for (int j = i; j < i + l; ++j) {
                if (a[j] == isz) {
                    cnt_for--;
                    if (cnt_for < 0) {
                        break;
                    }
                } else if (a[j] > isz) {
                    cnt_for++;
                }
            }
            if (cnt_for) {
                continue;
            }
            int j = l;
            for (; i + j < a.size(); ++j) {
                if (a[i + j] != a[i + j % l]) {
                    break;
                }
            }
            int cnt = j / l;
            if (cnt == 1 || cnt == 2 && l == 2) {
                continue;
            }
            a[i] = isz + cnt;
            for (j = 0; j < l; ++j) {
                a[i + 1 + j] = a[i + l + j];
            }
            a[i + 1 + l] = isz;
            for (j = i + cnt * l; j < a.size(); ++j) {
                a[j - cnt * l + 2 + l] = a[j];
            }
            a.resize(a.size() - cnt * l + 2 + l);
//            cerr << l << " " << i << " " <<  cnt << " " << a.size() << endl;
        }
    }
    int tab = 0;
    forn (i, a.size()) {
        if (a[i] == isz) {
            --tab;
            forn (j, tab) {
                cout << '\t';
            }
            cout << "end\n";
        } else if (a[i] < isz) {
            forn (j, tab) {
                cout << '\t';
            }
            cout << I[a[i]] << endl;
        } else {
            forn (j, tab) {
                cout << '\t';
            }
            ++tab;
            cout << "for-" << a[i] - isz << endl;
        }
    }
}

int main() {
//    freopen("tests/input-6.txt", "rt", stdin);
//    freopen("input1.txt", "wt", stdout);
    map<pair<int, int>, int> M;
    forn (i, 4) {
        M[make_pair(dx[i], dy[i])] = i;
    }
    int asdf;
    cin >> asdf >> asdf >> n >> m;
    int sx, sy;
    cin >> sx >> sy;
    int w, D, K, e;
    cin >> w >> D >> K >> e;
    w += D;
    forn (i, w) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        wall[x1][y1][M[mp(x2 - x1, y2 - y1)]] = true;
        wall[x2][y2][M[mp(x1 - x2, y1 - y2)]] = true;
    }
    forn (i, K) {
        cin >> asdf >> asdf;
    }
    forn (i, e) {
        int x, y;
        cin >> x >> y;
        ex[x][y] = true;
    }
    forn (i, n) {
        forn (j, m) {
            len[i][j] = 2000000000;
        }
    }
    vector<pair<int, int> > q;
    len[sx][sy] = 0;
    q.pb(mp(sx, sy));
    p[sx][sy] = mp(-1, -1);
    int l = 1;
    q.pb(mp(sx, sy));
    int rx = -1, ry = -1;
    while (l < q.size()) {
        int vx = q[l].fs, vy = q[l].sc;
        if (ex[vx][vy]) {
            rx = vx;
            ry = vy;
            break;
        }
        ++l;
        forn (i, 4) {
            int tx = vx + dx[i], ty = vy + dy[i];
            if (wall[vx][vy][i] || !ok(tx, ty) || len[tx][ty] <= len[vx][vy] + 1) {
                continue;
            }
            q.pb(mp(tx, ty));
            len[tx][ty] = len[vx][vy] + 1;
            p[tx][ty] = mp(vx, vy);
        }
    }
    cerr << len[rx][ry];
    vector<pair<int, int> > path;
    while (rx != -1) {
        path.pb(mp(rx, ry));
        int nx = p[rx][ry].fs, ny = p[rx][ry].sc;
        rx = nx;
        ry = ny;
    }
    vector<string> S;
    for (int i = path.size() - 1; i > 0; --i) {
//        cout << "move-" << name[M[mp(path[i - 1].fs - path[i].fs, path[i - 1].sc - path[i].sc)]] << endl;
        S.pb("move-" + name[M[mp(path[i - 1].fs - path[i].fs, path[i - 1].sc - path[i].sc)]]);
    }
    jpeg(S);
    return 0;
}