Buggy python submission (verdict: Runtime Error):
import copy
def amida(A,x):
  for e in A:
    if e[x]==1:x+=1
    elif e[x-1]==1:x-=1
  return x
def f():
  for i in range(d):
    for j in range(1,n):
      if A[i][j]==0:
        B=copy.deepcopy(A)
        B[i][j]=1
        if amida(B,m)==p:
          print i+1,j
          return
  print 1
  return
 
import sys
n=input()
m=input()
p=input()
d=input()
A=[]
for s in sys.stdin:
  if s=="0\n":break
  A+=[[0]+map(int,list(s[:-1]))+[0]]
if amida(A,m)==p: print 0
else:f()

Fixed submission:
import sys
def amida(A,x):
  for e in A:
    if e[x]=="1":x+=1
    elif e[x-1]=="1":x-=1
  return x
def f():
  for i in D:
    for j in range(1,n):
      if A[i][j-1:j+2]=="000":
        B=[e[:] for e in A]
        B[i]=B[i][:j]+"1"+B[i][j+1:]
        if amida(B,m)==p:
          print i+1,j
          return
  print 1
  return

while 1:
  n=input()
  if n==0:break
  m=input()
  p=input()
  D=range(input())
  A=["0"+raw_input()+"0" for i in D]
  if amida(A,m)==p:print 0
  else:f()

Buggy python submission (verdict: Runtime Error):
import copy,sys
def amida(A,x):
  for e in A:
    if e[x]==1:x+=1
    elif e[x-1]==1:x-=1
  return x
def f():
  for i in range(d):
    for j in range(1,n):
      if A[i][j]==0:
        B=copy.deepcopy(A)
        B[i][j]=1
        if amida(B,m)==p:
          print i+1,j
          return
  print 1
  return
n=input()
m=input()
p=input()
d=input()
A=[]
for s in sys.stdin:
  if s=="0\n":break
  A+=[[0]+map(int,list(s[:-1]))+[0]]
if amida(A,m)==p: print 0
else:f()

Fixed submission:
import sys
def amida(A,x):
  for e in A:
    if e[x]=="1":x+=1
    elif e[x-1]=="1":x-=1
  return x
def f():
  for i in D:
    for j in range(1,n):
      if A[i][j-1:j+2]=="000":
        B=[e[:] for e in A]
        B[i]=B[i][:j]+"1"+B[i][j+1:]
        if amida(B,m)==p:
          print i+1,j
          return
  print 1
  return

while 1:
  n=input()
  if n==0:break
  m=input()
  p=input()
  D=range(input())
  A=["0"+raw_input()+"0" for i in D]
  if amida(A,m)==p:print 0
  else:f()

Buggy python submission (verdict: Runtime Error):
import copy,sys
def amida(A,x):
  for e in A:
    if e[x]==1:x+=1
    elif e[x-1]==1:x-=1
  return x
def f():
  for i in range(d):
    for j in range(1,n+1):
      if A[i][j]==0:
        B=copy.deepcopy(A)
        B[i][j]=1
        if amida(B,m)==p:
          print i+1,j
          return
  print 1
  return

n=input()
m=input()
p=input()
d=input()
A=[]
for s in sys.stdin:
  if s=="0\n":break
  A+=[[0]+map(int,list(s[:-1]))+[0]]
if amida(A,m)==p: print 0
else:f()

Fixed submission:
import sys
def amida(A,x):
  for e in A:
    if e[x]=="1":x+=1
    elif e[x-1]=="1":x-=1
  return x
def f():
  for i in D:
    for j in range(1,n):
      if A[i][j-1:j+2]=="000":
        B=[e[:] for e in A]
        B[i]=B[i][:j]+"1"+B[i][j+1:]
        if amida(B,m)==p:
          print i+1,j
          return
  print 1
  return

while 1:
  n=input()
  if n==0:break
  m=input()
  p=input()
  D=range(input())
  A=["0"+raw_input()+"0" for i in D]
  if amida(A,m)==p:print 0
  else:f()

Buggy python submission (verdict: Runtime Error):
import sys
def amida(A,x):
  for e in A:
    if e[x]==1:x+=1
    elif e[x-1]==1:x-=1
  return x
def f():
  for i in range(d):
    for j in range(1,n):
      if A[i][j]==0:
        B=[e[:] for e in A]
        B[i][j]=1
        if amida(B,m)==p:
          print i+1,j
          return
  print 1
  return

n=input()
m=input()
p=input()
d=input()
A=[]
for s in sys.stdin:
  if s=="0\n":break
  A+=[[0]+map(int,list(s[:-1]))+[0]]
if amida(A,m)==p: print 0
else:f()

Fixed submission:
import sys
def amida(A,x):
  for e in A:
    if e[x]=="1":x+=1
    elif e[x-1]=="1":x-=1
  return x
def f():
  for i in D:
    for j in range(1,n):
      if A[i][j-1:j+2]=="000":
        B=[e[:] for e in A]
        B[i]=B[i][:j]+"1"+B[i][j+1:]
        if amida(B,m)==p:
          print i+1,j
          return
  print 1
  return

while 1:
  n=input()
  if n==0:break
  m=input()
  p=input()
  D=range(input())
  A=["0"+raw_input()+"0" for i in D]
  if amida(A,m)==p:print 0
  else:f()