using System;

namespace _069_DrawingLotsII
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;

			while ((inputStr = Console.ReadLine ()) != "0")
			{
				//input
				int lineCount = int.Parse (inputStr);
				int startNumber = int.Parse (Console.ReadLine ());
				int hitNumber = int.Parse (Console.ReadLine ());
				int stageNumber = int.Parse (Console.ReadLine ());
				string[] map = new string[stageNumber];
				for (int lp = 0; lp < stageNumber; lp++)
				{
					map[lp] = Console.ReadLine ();
				}

				//process
				Solve.SetData (lineCount, startNumber, hitNumber, stageNumber, map);
				var result = Solve.Result ();
				Console.WriteLine (result);
			}
		}

		static class Solve
		{
			private static int LineCount { set; get; }
			private static int StartNumber { set; get; }
			private static int HitNumber { set; get; }
			private static int StageNumber { set; get; }
			private static char[][] Map { set; get; }
			const char Exist = '1';
			const char NotExist = '0';

			private static int[] PositionMemory { set; get; }

			public static void SetData ( int lineCount, int startNumber, int hitNumber, int stageCount, string[] map )
			{
				//copy
				LineCount = lineCount;
				StartNumber = startNumber - 1;
				HitNumber = hitNumber - 1;
				StageNumber = stageCount;
				Map = new char[stageCount][];
				for (int lp = 0; lp < Map.Length; lp++)
				{
					Map[lp] = map[lp].ToCharArray ();
				}
			}

			public static string Result ()
			{
				//process
				PositionMemory = new int[StageNumber];

				//????????????????????????
				if (IsHit2 () || LineCount == 1)
				{
					return "0";
				}

				for (int height = 0; height < StageNumber; height++)
				{
					if (IsLeft (height))
					{
						return (height + 1) + " " + (PositionMemory[height]);
					}
					else if (IsRight (height))
					{
						return (height + 1) + " " + (PositionMemory[height] + 1);
					}
				}

				return "1";
			}

			private static bool IsLeft ( int height )
			{
				//1??¬??????
				int changePoint = PositionMemory[height];

				bool isLeft = 0 <= changePoint - 1;

				//????????????map??????????????????IsHit???????????????

				if (isLeft)
				{
					if (Map[height][changePoint - 1] == NotExist)
					{
						//2?????£?¶???§?????°?????????????????????
						//???????????¨?????????
						if (0 <= changePoint - 2)
						{
							if (Map[height][changePoint - 2] == Exist)
							{
								return false;
							}
						}

						//???????????¨?????????
						if (changePoint < Map[height].Length)
						{
							if (Map[height][changePoint] == Exist)
							{
								return false;
							}
						}

						Map[height][changePoint - 1] = Exist;
						bool result = IsHit ();
						Map[height][changePoint - 1] = NotExist;
						return result;
					}
				}

				return false;
			}

			private static bool IsRight ( int height )
			{
				//1??¬??????
				int changePoint = PositionMemory[height];

				bool isRight = changePoint < Map[height].Length;

				//????????????map??????????????????IsHit???????????????

				if (isRight)
				{
					if (Map[height][changePoint] == NotExist)
					{
						//2?????£?¶???§?????°?????????????????????

						//???????????¨?????????
						if (0 <= changePoint - 1)
						{
							if (Map[height][changePoint - 1] == Exist)
							{
								return false;
							}
						}

						//???????????¨?????????
						if (changePoint + 1 < Map[height].Length)
						{
							if (Map[height][changePoint + 1] == Exist)
							{
								return false;
							}
						}

						Map[height][changePoint] = Exist;
						bool result = IsHit ();
						Map[height][changePoint] = NotExist;
						return result;
					}
				}

				return false;
			}

			private static bool IsHit ()
			{
				int position = StartNumber;

				for (int height = 0; height < StageNumber; height++)
				{
					bool isThrough = false;

					//????????????
					if (0 <= position - 1)
					{
						if (Map[height][position - 1] == Exist)
						{
							position--;
							isThrough = true;
						}
					}
					//????????????
					if (position < Map[height].Length && !isThrough)
					{
						if (Map[height][position] == Exist)
						{
							position++;
						}
					}
				}

				return position == HitNumber;
			}

			private static bool IsHit2 ()
			{
				int position = StartNumber;

				for (int height = 0; height < StageNumber; height++)
				{
					bool isThrough = false;

					//????????????
					if (0 <= position - 1)
					{
						if (Map[height][position - 1] == Exist)
						{
							position--;
							isThrough = true;
						}
					}
					//????????????
					if (position < Map[height].Length && !isThrough)
					{
						if (Map[height][position] == Exist)
						{
							position++;
						}
					}

					PositionMemory[height] = position;
				}

				return position == HitNumber;
			}
		}
	}
}

Measured memory_bytes: 9264