Help me in solving DSSA19 problem

My issue

My code

# cook your dish here

T=int(input())
for i in range(T):
    N=int(input())
    towexs=input()
    count=0
    if towexs[0:2]=="00":
        towexs="1"+towexs[1:]
        count+=1
    if towexs[-2:]=="00":
        towexs=towexs[:-1]+"1"
        count+=1
    i=1
    while i<N-1:
        if towexs[i-1:i+2]=="000":
            towexs=towexs[:i]+"1"+towexs[i+1:]
            count+=1
            i+=2
        else:
            i+=1
    print(count)
        

Learning course: Kalasalingam Academy of Research and Education
Problem Link: CodeChef: Practical coding for everyone