#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main(){
        int n; 
        cin >> n; 
        while(n){
                int m,g,d;
                cin >> m >> g >> d; 
                int kuji[d][n+1];
                memset(kuji,0,sizeof(kuji));
                for(int i = 0; i < d; i++){
                        int tmp;
                        cin >> tmp;
                        for(int j = n-1; j > 0; j--){
                                kuji[i][j] = tmp%10;
                                tmp /= 10;
                        }  
                }  
                int num[d+1][n+2];
                memset(num,0,sizeof(num));
                for(int i = 0; i < n; i++){
                        num[0][i+1] = i+1;
                }  
                for(int i = 0; i < d; i++){
                        memcpy(num[i+1], num[i], sizeof(num[i]));
                        for(int j = 1; j < n; j++){
                                if(kuji[i][j]) swap(num[i+1][j],num[i+1][j+1]);
                        }  
                }  
                if(num[d][g] == m) cout << 0 << endl;
                else{
                        bool f = true;
                        int s[2] = {num[d][g], m};
                        sort(s, s+2);
                        for(int i = 0; i < d; i++){
                                for(int j = 1; f && j < n; j++){
                                        int t[2] = {num[i][j], num[i][j+1]};
                                        sort(t, t+2);
                                        if(memcmp(s,t,sizeof(s)) == 0){
                                                if(kuji[i][j-1] + kuji[i][j] + kuji[i][j+1] == 0){
                                                        cout << i+1 << " " << j << endl;
                                                        f = false;
                                                }  
                                        }  
                                }  
                        }  
                        if(f) cout << 1 << endl;
                }  
                cin >> n; 
        }  
}