#include <bits/stdc++.h>
usingnamespacestd;intdp[205][205];// dp[i][j] denotes the maximum length possible for a[i] to a[j] (i <= j)intsolve(inti,intj,strings){if(i==j){// base case: one length stringif(s[i]=='1'){returndp[i][j]=1;}returndp[i][j]=0;}// memoization partif(dp[i][j]!=-1){returndp[i][j];}// if in string from i-th index to j-th index, count of 1's is more, // then the entire length from i to j is the answerintcount1=0,count0=0;for(intk=i;k<=j;k++){if(s[k]=='0'){count0++;}else{count1++;}}if(count1>count0){returndp[i][j]=j-i+1;// entire length}dp[i][j]=0;// try all possible partitions, select one that yields maximum dp[i][j]for(intk=i;k<j;k++){if(solve(i,k,s)+solve(k+1,j,s)>dp[i][j]){dp[i][j]=solve(i,k,s)+solve(k+1,j,s);}}returndp[i][j];}intmain(){strings;intt,n;cin>>t;for(inti=0;i<t;i++){cin>>n;cin>>s;// intialize dp tablefor(intj=0;j<n;j++){for(intk=0;k<n;k++){dp[j][k]=-1;}}cout<<solve(0,n-1,s)<<"\n";}/*/
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cout << dp[i][j] << " ";
}
cout << "\n";
}
//*/return0;}