#include "testlib.h"

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

int n, m;
bool used[N][N];

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

void addWalls(int x, int y, std::vector<std::pair<int, int>>& walls, std::vector<std::string>& field) {
    for (int i = 0; i < 4; ++i) {
        int newX = x + dx[i];
        int newY = y + dy[i];
        if (!isCorrect(newX, newY) || used[newX][newY] || field[newX][newY] != '#') {
            continue;
        }
        used[newX][newY] = true;
        walls.emplace_back(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';
    used[x][y] = true;
    std::vector<std::pair<int, int>> walls;
    addWalls(x, y, walls, a);

    for (int it = 0; it < pathLen && !walls.empty(); ++it) {
        int i = rnd.wnext(0, (int)walls.size() - 1, mode);
        auto[newX, newY] = walls[i];
        std::swap(walls[i], walls.back());
        walls.pop_back();
        a[newX][newY] = '.';
        addWalls(newX, newY, walls, a);
        x = newX;
        y = newY;
    }
    a[x][y] = 'f';

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

    return 0;
}
