#include "testlib.h"

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

int n, m;
int prevX = -1, prevY = -1;

std::pair<int, int> generateMove(int x, int y, int mode) {
    while (true) {
        int t = rnd.next(0, 3);
        int newX = x + dx[t];
        int newY = y + dy[t];
        if (newX < 0 || newY < 0 || newX >= n || newY >= m) {
            continue;
        }
        if (mode == 1 && prevX == newX && prevY == newY) {
            continue;
        }

        prevX = x;
        prevY = y;
        return std::make_pair(newX, newY);
    }
}

int main(int argc, char** argv) {
    registerGen(argc, argv, 1);
    
    std::cout << 1 << std::endl;

    n = atoi(argv[1]);
    m = atoi(argv[2]);
    int pathLen = atoi(argv[3]);
    int mode = atoi(argv[4]);

    std::cout << n << ' ' << m << std::endl;
    
    std::vector<std::string> a(n);
    for (int i = 0; i < n; ++i) {
        a[i].resize(m, '#');
    }

    int x = rnd.next(0, n - 1);
    int y = rnd.next(0, m - 1);
    a[x][y] = 's';
    for (int i = 0; i < pathLen; ++i) {
        auto[newX, newY] = generateMove(x, y, mode);
        x = newX;
        y = newY;
        if (a[x][y] != 's') {
            a[x][y] = '.';
        }
    }
    if (a[x][y] == 's') {
        auto[newX, newY] = generateMove(x, y, mode);
        x = newX;
        y = newY;
    }
    a[x][y] = 'f';

    for (int i = 0; i < n; ++i) {
        std::cout << a[i] << std::endl;
    }

    return 0;
}
