{$q+,r+}
uses
    sysutils;
const
    max_n = 10;
    dx: array [0..3] of longint = (0, 0, 1, -1);
    dy: array [0..3] of longint = (1, -1, 0, 0);

procedure generate(n, m, z: longint; p: double);
    function ok(i, j: longint): boolean;
    begin
        result := (1 <= i) and (i <= n) and (1 <= j) and (j <= m);
    end;

var
    a: array [1..max_n, 1..max_n] of boolean;
    i, j, d: longint;
begin
    fillchar(a, sizeof(a), 0);

    a[random(n) + 1][random(m) + 1] := true;

    for z := 1 to z do begin
        repeat
            i := random(n) + 1;
            j := random(m) + 1;
        until a[i][j];

        d := random(4);
        while random > p do begin
            if random > 0.8 then begin
                d := random(4);
            end;
            if ok(i + dx[d], j + dy[d]) then begin
               i := i + dx[d];
               j := j + dy[d];
               a[i][j] := true;
            end;
        end;
    end;

    writeln(n, ' ', m);
    for i := 1 to n do begin
        for j := 1 to m do begin
            if a[i][j] then write('*') else write('.');
        end;
        writeln;
    end;
end;
    
begin
    decimalseparator := '.';
    randseed := strToInt(paramstr(1));
    generate(
        strToInt(paramstr(2)),
        strToInt(paramstr(3)),
        strToInt(paramstr(4)),
        strToFloat(paramstr(5)),
    );       
    generate(
        strToInt(paramstr(6)),
        strToInt(paramstr(7)),
        strToInt(paramstr(8)),
        strToFloat(paramstr(9)),
    );       
end.
