#include using namespace std; // Short forms #define int long long #define ll long long #define endl '\n' #define ff first #define ss second #define pb push_back #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() // Outputs #define yes cout<<"YES"< void _print(pair p); template void _print(vector v);template void _print(set v); template void _print(map v);template void _print(multiset v); template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template void _print(unordered_set v) {cerr<<"[ "; for(T i : v) {_print(i); cerr<<" ";} cerr<<"]";} template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} template void _print(multimap v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} template void _print(unordered_map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void solve() { string s; cin>>s; if(sz(s)==1) { cout<<1<ct0) { diff=ct1-ct0; for(int i=sz(s); i>=0; --i) { if(s[i]=='1') { diff--; } if(diff==0) break; ans++; } } else { diff=ct0-ct1; for(int i=sz(s); i>=0; --i) { if(s[i]=='0') { diff--; } if(diff==0) break; ans++; } } cout<> TC; while (TC--) solve(); }