#include using namespace std; const int N=110000; int t,n,ans,ss1[N],ss2[N],t1[N],t2[N],ct1[5],ct2[5]; char ch[N]; inline int read(){ int z=0,f=1; char c=getchar(); while(c<'0'||c>'9'){ if(c=='-')f=-1; c=getchar(); } while(c>='0'&&c<='9'){ z=(z<<1)+(z<<3)+(c^48); c=getchar(); } return z*f; } int main(){ freopen("edit.in","r",stdin); freopen("edit.out","w",stdout); t=read(); while(t--){ for(int i=0; i<=1; i++)ct1[i]=0,ct2[i]=0; ans=0; n=read(); scanf("%s",ch); for(int i=0; ir){ ct2[ss2[r]]++,r++; if(ct2[1]<=ct1[1])ans+=ct2[1],ct1[1]-=ct2[1]; else ans+=ct1[1],ct1[0]-=ct2[1]-ct1[1],ct1[1]=0; if(ct2[0]<=ct1[0])ans+=ct2[0],ct1[0]-=ct2[0]; else ans+=ct1[0],ct1[1]-=ct2[0]-ct1[0],ct1[0]=0; ct2[1]=0,ct2[0]=0; //printf("%d %d %d\n",l,r,ans); } } printf("%d\n",ans); } } /* 1 9 101111111 100111000 110111011 011111111 */