#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

vector<vector<pair<int,int> > >vec;
vector<pair<int,int> >v;
int n,m,l,d,cur,dep,mi,de;
char b;

void go(){
    cur=m,dep=0;
    while(dep<d){
        for(int i=0;i<vec[dep].size();i++){
            if(vec[dep][i].first==cur){
                cur=vec[dep][i].second;
                break;
            }
            if(vec[dep][i].second==cur){
                cur=vec[dep][i].first;
                break;
            }
        }
        dep++;
    }
}

int main(){
    while(cin>>n,n){
        vec.clear();
        cin>>m>>l>>d;
        for(int i=0;i<d;i++){
            vec.push_back(v);
            for(int j=1;j<n;j++){
                cin>>b;
                if(b=='1')
                    vec[i].push_back(make_pair(j, j+1));
            }
        }
        go();
        if(cur==l){
            cout<<0<<endl;
            goto ne;
        }
        mi=99,de=0;
        for(int i=1;i<n;i++){
            for(int j=0;j<d;j++){
                vec[j].push_back(make_pair(i, i+1));
                go();
                if(cur==l){
                    if(abs(cur-m)<abs(mi-m)){
                        mi=i;
                        de=j;
                    }
                }
                vec[j].pop_back();
            }
        }
        if(mi!=99)cout<<de<<" "<<mi<<endl;
        else cout<<1<<endl;
    ne:;
    }
    
}