from typing import *

def getMaxLen(arr: List[int]):
    if 0 not in arr:
        return len(arr)-1

    new_arr, count = [], 0
    for each in arr:
        if each == 0:
            if count != 0:
                new_arr.append(count)
                count = 0
            new_arr.append(0)
        else:
            count += 1
    if count != 0:
        new_arr.append(count)

    maxLen = max(new_arr)
    for i in range(1, len(new_arr)-1):
        if new_arr[i] == 0 and new_arr[i-1] != 0 and new_arr[i+1] != 0:
            maxLen = max(new_arr[i-1] + new_arr[i+1], maxLen)
    return maxLen


if __name__=='__main__':
    T = int(input())
    for _ in range(T):
        N = int(input())
        arr = input().split(' ')
        arr = [int(each) for each in arr]
        print(getMaxLen(arr))
