/*
* @author Md. Fahmidur Rahman Nafi
* @create date 05-11-2024 21:17:29
*/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define ld long double
#define ull unsigned long long
#define lcm(a,b) ((a*b)/__gcd(a,b))
const int MOD = 1000000007;
void solve(){
int n;
cin >> n;
string s;
cin >> s;
int zero = count(s.begin(), s.end(), '0');
int one = count(s.begin(), s.end(), '1');
if (n == one){
cout << 0 << endl;
return;
}
else if (n == zero){
cout << n << endl;
return;
}
int seq = 0;
int count = 0;
for (int i = 0; i < n; i++){
if (s[i] == '0'){
seq++;
}
else{
seq = 0;
}
count = max(seq, count);
}
cout << count << endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--){
solve();
}
}