#include <bits/stdc++.h>
#define endl "\n"
#define Dark_knight
#include <complex.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;
typedef long long ll;
#define int long long
const int N = 2e5 + 2;
const int mod = 1073741824;
long long arr[N]={};
long long pref[N]={};
int lcm(int a , int b ) {
    return  a/__gcd(a,b) *b;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t ;
    cin  >> t;
    while(t--) {
        int n ;
        cin >> n ;
        string s ;
        cin >> s;
        int ctr = 0 , mx = 0  ;
        for(int i = 0 ;  i < n ; i++) {
            if(s[i]=='0') {
                ctr++;
            }
            else {
                mx=max(ctr,mx);
                ctr=0;
            }
        }
        mx=max(ctr,mx);
        int begin = 0 ;
        for(int i = 0 ;  i < n ; i++) {
            if(s[i]=='0') {
                begin++;
            }
            else {
               break;
            }
        }
        int trail = 0 ;
        for(int i = n-1 ; i >= 0 ; i++ ) {
            if(s[i]=='0') {
                trail++;
            }
            else {
                break;
            }
        }
        cout<<max(mx,begin+trail)<<endl;

    }

}


