#include <stdio.h>
#define SIZE 50

int main() {
    int floor[SIZE][SIZE] = {0};
    int commands[] = {2, 5, 12, 3, 5, 12, 3, 5, 12, 3, 5, 12, 1, 6, 9};
    int commandIndex = 0;
    int penDown = 0;
    int direction = 0; 
    int currentRow = 0;
    int currentCol = 0;

    while (commands[commandIndex] != 9) {
        int command = commands[commandIndex];
        
        if (command == 1) {
            penDown = 0;
            commandIndex++;
        } else if (command == 2) {
            penDown = 1;
            commandIndex++;
        } else if (command == 3) {
            direction = (direction + 1) % 4;
            commandIndex++;
        } else if (command == 4) {
            direction = (direction + 3) % 4;
            commandIndex++;
        } else if (command == 5) {
            commandIndex++;
            int spaces = commands[commandIndex];
            
            for (int i = 0; i < spaces; i++) {
                if (penDown) {
                    floor[currentRow][currentCol] = 1;
                }
                
                if (direction == 0 && currentCol < SIZE - 1) {
                    currentCol++;
                } else if (direction == 1 && currentRow < SIZE - 1) {
                    currentRow++;
                } else if (direction == 2 && currentCol > 0) {
                    currentCol--;
                } else if (direction == 3 && currentRow > 0) {
                    currentRow--;
                }
            }
            if (penDown) {
                floor[currentRow][currentCol] = 1;
            }
            commandIndex++;
        } else if (command == 6) {
            for (int r = 0; r < SIZE; ++r) {
                for (int c = 0; c < SIZE; ++c) {
                    if (floor[r][c] == 1) {
                        printf("*");
                    } else {
                        printf(" ");
                    }
                }
                printf("\n");
            }
            commandIndex++;
        }
    }

    return 0;
}