#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T = int>inline T in() { T x; cin >> x; return x; }
#define REP(i,n) for(ll i=0;i<(n);++i)
#define REP1(i,n) for(ll i=1;i<=(n);++i)
#define REPI(i,ini,n) for(ll i=(ini);i<(n);++i)
#define REPC(i,obj) for(auto i:obj)
#define R_UP(a,b) (((a)+(b)-1)/(b))
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1e9
#define INFL static_cast<ll>(INF)
#define LEFT 0
#define RIGHT 1
int get_digit(int num, int digit)
{
	REP(i, digit)num /= 10;
	return num % 10;
}
bool solve_amida(int col, int row, int*pass, int s, int g)
{
	int x = s;
	REP(y, row)
	{
		if (x != 1 && get_digit(pass[y], col - x) == 1)--x;
		else if (x != col && get_digit(pass[y], col - x - 1) == 1)++x;
	}
	if (x == g)
	{
		cout << '0' << endl;
		return true;
	}
	return false;
}
bool solve_amida(int col, int row, int*pass, int s, int g, int new_pass, int dir)
{
	int x = s;
	REP(y, new_pass)
	{
		if (x != 1 && get_digit(pass[y], col - x) == 1)--x;
		else if (x != col && get_digit(pass[y], col - x - 1) == 1)++x;
	}
	if (dir == LEFT && (x == 1 || x > 2 && get_digit(pass[new_pass - 1], col + 2 - x) == 1 || x != col && get_digit(pass[new_pass - 1], col - x - 1) == 1) || dir == RIGHT && (x == col || x < col - 1 && get_digit(pass[new_pass - 1], col - 2 - x) == 1 || x != 1 && get_digit(pass[new_pass - 1], col - x) == 1))return false;
	int col_num;
	switch (dir)
	{
	case LEFT:
		x--;
		col_num = x;
		break;
	case RIGHT:
		col_num = x;
		x++;
		break;
	}
	REPI(y, new_pass, row)
	{
		if (x != 1 && get_digit(pass[y], col - x) == 1)--x;
		else if (x != col && get_digit(pass[y], col - x - 1) == 1)++x;
	}
	if (x == g)
	{
		cout << new_pass << ' ' << col_num << endl;
		return true;
	}
	return false;
}
int main()
{
	while (true)
	{
		int col = in();
		if (col == 0)break;
		int s = in(), g = in(), row = in();
		int*pass = new int[row];
		REP(i, row)pass[i] = in();
		if (!solve_amida(col, row, pass, s, g))
		{
			REP(i, row)REP(j, 2)
			{
				if (solve_amida(col, row, pass, s, g, i, j))goto roop_end;
			}
			cout << '1' << endl;
		roop_end:
			;
		}
	}
}
