I am getting wrong answer for this question can any1 please help where i went wrong

#include <bits/stdc++.h>

using namespace std;

int main()

{

int t;

cin>>t;

while(tβ)

{

string s;

cin>>s;

int n1=0;

int n0=0;

int n=s.size();

```
for(int i=0;i<n;i++)
{
if(s[i]=='1')
{
n1++;
}
else
{
n0++;
}
}
if(n%2!=0)
{
cout<<-1<<endl;
}
else if(n0==0 || n1==0)
{
cout<<0<<endl;
}
else
{
if(n1==n0)
{
cout<<0<<endl;
}
else
{
int k1=max(n1,n0);
int k2=min(n1,n0);
int ans=(k1-k2)/2;
cout<<ans<<endl;
}
}
}
return 0;
```

}