import java.util.Scanner;
public class Game {
    
    private static int[][] board = new int[4][4];
    private static boolean selected = false;
    
    public static void main(String [] args){
        int curPos = 0; // tens is x, ones is y
        Scanner scan = new Scanner(System.in);
        setBoard();
        while(checkBoard()){
            shuffle();
        }
        
        while (!checkBoard()){
            printBoard(curPos,selected);
            String s = scan.nextLine();
            switch(s){
                case "w":
                if(selected){
                    move(curPos,1,true);
                }else{
                    curPos = ((curPos-1)%10 == 9 || (curPos-1)%10 < 0  ? curPos+3 : curPos-1);
                }
                break;
                case "s":
                if(selected){
                    move(curPos,3,true);
                }else{
                    curPos = ((curPos+1)%10 == 4 ? curPos - 3 : curPos+1);
                }
                break;
                case "a":
                if(selected){
                    move(curPos,1,false);
                }else{
                    curPos = ((curPos-10) < 0 ? curPos+30 : curPos-10);
                }
                break;
                case "d":
                if(selected){
                    move(curPos,3,false);
                }else{
                    curPos = ((curPos+10)/10 == 4 ? curPos-30 : curPos+10);
                }
                break;
                case "e":
                selected = !selected;
                default:
                break;
            }
        }
        scan.close();
    }
    
    public static void setBoard(){
        for(int i = 0; i < board.length; i++){
            for(int j = 0; j < board[i].length; j++){
                board[i][j] = 4*i+j+1;
            }
        }
    }
    
    public static void printBoard(int pos, boolean selected){
        for(int i = 0; i < board.length; i++){
            for(int j = 0; j < board[i].length; j++){
                if(i == pos%10 && j == pos/10){
                    if(!selected){
                        System.out.printf("[%s]",(board[i][j] < 10 ? "0" : "") + board[i][j]);
                    }else{
                        System.out.printf("{%s}",(board[i][j] < 10 ? "0" : "") + board[i][j]);
                    }

                }else{
                    System.out.printf(" %s ",(board[i][j] < 10 ? "0" : "") + board[i][j]);
                }
            }
            System.out.println();
        }
    }
    
    public static void move(int pos, int times, boolean vert){
        for(int j = 0; j < times; j++){
            int temp = (vert ? board[0][pos/10] : board[pos%10][0]);//y,x
            for(int i = 0; i < board.length - 1; i++){
                if(vert){
                    board[i][pos/10] = board[i+1][pos/10];
                }else{
                    board[pos%10][i] = board[pos%10][i+1];
                }
                
            }
            if(vert){
                board[3][pos/10] = temp;
            }else{
                board[pos%10][3] = temp;
            }
        }
    }
    public static boolean checkBoard(){
        for(int i = 0; i < board.length; i++){
            for(int j = 0; j < board[i].length; j++){
                if(board[i][j] != 4*i+j+1){
                    return false;
                }
            }
        }
        return true;
    }
    
    public static void shuffle(){
        int[] vals = {0,1,2,3,10,11,12,13,20,21,22,23,30,31,32,33};
        for(int i = 0; i < 2000; i++){
            move(vals[(int)(Math.random()*16)],(int)(Math.random()*3)+1,(int)(Math.random()*2)==1);
        }
    }
}