import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

string solve(immutable int n)
{
    auto t = iota(3).map!(_=>readln().chomp().to!int());
    immutable m=t[0], p=t[1], d=t[2];
    auto g = iota(d).map!(_=>readln().chomp().map!(c=>c=='1').array()).array();
    auto a = iota(1,n+1).array();
    foreach(e;g) foreach(i,v;e) if(v) swap(a[i],a[i+1]);
    immutable h=a[p-1];
    if(m==h) return "0";
    a = iota(1,n+1).array();
    foreach(j,e;g)
    {
        foreach(i,v;e) if(v) swap(a[i],a[i+1]);
        foreach(i,v;a) if(v==m || v==h)
        {
            if((a[i+1]==m || a[i+1]==h) && (i<=0 || !e[i-1]) && !e[i] && (i+1>=e.length || !e[i+1]))
                return format("%s %s",j+1,i+1);
            break;
        }
    }
    return "1";
}

void main()
{
    for(int n; 0!=(n=readln().chomp().to!int()); )
        writeln(solve(n));
}