#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<string.h>
#include <stdio.h>
#include<math.h>
#include<functional>



using namespace std;

int amida_test(int now_row, int now_col, int yoko[30][12]){
    for(int i=0; i<30; i++){
        if(yoko[now_col][now_row]==1){
            now_row++;
        }else if(yoko[now_col][now_row-1]==1){
            now_row--;
        }
        now_col++;
    }
    return now_row;
}

int amida(int now_row, int now_col, int yoko[30][12], int goal, int col_max){
    if(now_col==col_max){
        return 1;
    }
    if(yoko[now_col][now_row]==1){
        now_row++;
    }else if(yoko[now_col][now_row-1]==1){
        now_row--;
    }else{
        if(now_row!=10&&yoko[now_col][now_row+1]==0){
            int temp = amida_test(now_row+1, now_col+1, yoko);
            if(temp==goal){
                cout<<now_col+1<<' ';;
                return now_row;
            }
        }
        if(now_row!=1&&yoko[now_col][now_row-2]==0){
            int temp = amida_test(now_row-2, now_col+1, yoko);
            if(temp==goal){
                cout<<now_col+1<<' ';
                return now_row-1;
            }
        }
    }
    now_col++;
    return amida(now_row, now_col, yoko, goal, col_max);
    
}




int main(){
    int row_max,start,goal,col_max;
    while(cin>>row_max){
        if(row_max==0)break;
        cin>>start>>goal>>col_max;
        

        
        
        int yoko[30][12]={0};

        for(int i=0; i<col_max; i++){
            for(int j=1; j<row_max; j++){
                char temp;
                cin>>temp;
                yoko[i][j]=temp-'0';
            }
        }
        for(int i=0; i<col_max; i++){
            for(int j=0; j<12; j++){
                cout<<yoko[i][j];
            }
            cout<<endl;
        }
        
        if(amida_test(start, 0, yoko)==goal)cout<<0<<endl;
        else cout<<amida(start, 0, yoko, goal, col_max)<<endl;

    }
    
    
    
    /*
     5
     2
     2
     9
     1010
     1001
     0100
     1001
     0010
     1000
     0100
     0101
     1010
     
     */
}