   //______________RD_THE_NOOB_______________________\\
  //_____________Iron_Man_3000love____________________\\
 //__________GOD ______IS_______ALMIGHTY_______________\\

#include <bits/stdc++.h>
using namespace std;

#define      inl(x)              scanf("%lld",&x)
#define      in(x)               scanf("%d",&x)
#define      mxx                 10000000000000
#define      mnn                 -10000000000000
#define      Y()                 cout<< "YES" <<endl
#define      N()                 cout << "NO"<<endl
#define      max_3(a,b,c)        max(a, max(b,c))
#define      max_4(a,b,c,d)      max(a,max(b,max(c,d)))
#define      min_3(a,b,c)        min(a, min(b,c))
#define      min_4(a,b,c,d)      min(a,min(b,min(c,d)))
#define      gcd(a,b)            __gcd(a,b)
#define      lcm(a,b)           (a*b)/gcd(a,b)
#define      bye                 return 0
#define      ll                  long long
#define      pi                  2 * acos(0.0)
#define      PI                  acos(-1)
#define      mem(a,v)            memset(a,v,sizeof(a))
#define      SET2d(x,m,n)        memset(x, 0, sizeof(x[0][0]) * m * n)
#define      SETBOOL(x)          memset(x,false,sizeof(x))
#define      CLR(x)              memset(x, -1, sizeof(x))
#define      SORT(v)             sort(v.begin(),v.end())
#define      REV(v)              reverse(v.begin(),v.end())
#define      erasee(v)           v.erase(unique(v.begin(),v.end()),v.end())
#define      FOR(i,a,b)          for(int i=a;i<=b;i++)
#define      ROF(i,a,b)          for(int i=a;i>=b;i--)
#define      REP(i,b)            for(int i=0;i<b;i++)
#define      O(x)                cout<<x<<endl
#define      W(x)                ll x; cin>>x; while(x--)
#define      mod                 998244353
#define      G                   getline
#define      SZ                  size()
#define      C                   clear()
#define      B                   begin()
#define      FR                   front()
#define      T                   top()
#define      E                   end()
#define      EM                  empty()
#define      V                   vector
#define      Q                   queue
#define      DQ                  deque
#define      PQ                  priority_queue
#define      ST                  stack
#define      F                   first
#define      S                   second
#define      PS                  push
#define      PP                  pop()
#define      PSF                 push_front
#define      PSB                 push_back
#define      EMB                 emplace_back
#define      PPF                 pop_front()
#define      PPB                 pop_back()
#define      MP                  make_pair
#define      ULL                 unsigned long long int
#define      PII                 pair<int,int>
#define      PSI                 pair<string,int>
#define      PIS                 pair<int,string>
#define      PLI                 pair<long long int,int>
#define      PLL                 pair<long long int,long long int>
#define      MII                 map<int,int>
#define      MSI                 map<string,int>
#define      MIS                 map<int,string>
#define      MLI                 map<long long int,int>
#define      FAST()              ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//const ll MOD = 998244353;
//auto it=std:: unique(v.B,v.E);
//v.resize(std::distance(v.B,it));
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

/*----*/

bool primeCheck(ll n){if(n%2 == 0)return false; for(ll i=3;i*i<=n;i+=2){if(n%i == 0)return false;}return true;}
ll power(ll n,ll p){if(p==0) return 1;if(p==1)return n;if(p%2)return power(n,p-1)*n;else{ll x=power(n,p/2);return x*x;}}
ll fact(ll num){ll fac=1;while(num!=1){fac=fac*num;num--;}return fac;}
int binaryToDecimal(string n){string num=n;int dec_value=0;int base=1;int len=num.length();for(int i=len-1;i>=0;i--){if(num[i]=='1')dec_value+=base;base=base*2;}return dec_value;}
string twostringdigitsum(string a, string b){ string s=""; while(a.size()<b.size()) {a='0'+a;} while(a.size()>b.size()) {b='0'+b;} ll c=0;
 for (ll i=a.size()-1;i>=0;i--){c+=(a[i]-'0')+(b[i]-'0'); s=char((c%10)+'0')+s; c/=10;} while(c>0){s=char((c%10)+'0')+s;c/=10;}return s;}
ll stringdigitsum(string digits){ll num,total=0; for(int i = 0; i < digits.length(); i++){num = digits.at(i) - '0';assert(0 <= num && num <= 9);total += num;}return total;}
ll integerdigitsum(ll n){ll sum=0;while(1){if(n<10){ sum+=n; break;}else{sum+=n%10;n/=10;}}return sum;}

/*-----*/
bool ispal(string s){
    ll i=0;
    ll j=s.size()-1;
    while(i<j){
        if(s[i]!=s[j]) return false;
        i++;
        j--;
    }
    return true;
}
const int N=2e5+5;
void scan(ll &n) { scanf("%lld",&n) ; }
void scan(ll &n, ll &m) { scanf("%lld%lld",&n,&m) ; }
void scan(vector<ll> &v) { ll n = v.size() ; for(ll i=0 ;i<n;i++) scanf("%lld",&v[i]) ; }
vector<ll> adj[N] ;
ll vis[N] , lvl[N] ,lvl1[N],vis1[N] ;
void edge (ll u , ll v) {
    adj[u].PSB(v) ;
    adj[v].PSB(u) ;
}

void dfs(ll n){
  vis[n]=1;
  ll tot=1;
  for(auto it: adj[n]){
    if(!vis[it]){
        dfs(it);
        tot+=lvl[it];
    }
  }
  lvl[n]=tot;
}

void bfs(ll n){
   vis1[n]=1;
   queue<ll> q;
   q.push(n);
   lvl1[n]=0;
   while(!q.empty()){
    ll f=q.front();
    q.pop();
    for(auto it: adj[f]){
        if(!vis1[it]){
            q.push(it);
            lvl1[it]=lvl1[f]+1;
            vis1[it]=1;
        }
    }
   }
}

/*-----*/
//vector<int> v[202];

int main()
{

	FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

       ll t=1;
       cin>>t;
       while(t--){
           ll n,i,j;
           string s1;
           cin>>n;
           V<string> ans(n);
           set<string> st1,st2;
           for(i=0;i<n;i++){
            cin>>ans[i];
            st1.insert(ans[i]);
           }
           ll cnt=0;
           for(i=0;i<n;i++){
            if(!st2.count(ans[i]))
                st2.insert(ans[i]);
            else{
                cnt++;
                for(j=0;j<10;j++){
                    ans[i][0]='0'+j;
                    if(!st1.count(ans[i])){
                        st1.insert(ans[i]);
                        break;
                    }
                }
            }
           }
           cout<<cnt<<endl;
           for(auto it : ans)
           cout<<it<<endl;
          // cout<<endl;

        }

	bye;

}

        /*Keep Me In Your Prayer*/


/*
       //......................................*
      //     Rudro Debnath                     *
      //     Dept Of CSE                       *
      //     University Of Barisal             *
      //****************************************
  _______________________________________________________
 /______GOD ______IS__________ALMIGHTY__________________/

 */

#include <bits/stdc++.h>
using namespace std;

#define inl(x) scanf("%lld",&x)
#define in(x)  scanf("%d",&x)
#define mxx 10000000000000
#define Y() cout<< "YES" <<endl
#define N() cout << "NO"<<endl
#define max_3(a,b,c) max(a, max(b,c))
#define max_4(a,b,c,d) max(a,max(b,max(c,d)))
#define min_3(a,b,c) min(a, min(b,c))
#define min_4(a,b,c,d) min(a,min(b,min(c,d)))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define bye return 0
#define ll long long
#define pi  2 * acos(0.0)
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{

	FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

      ll t,n,i,j,ct=0,ck=0,f=0,d=0,e=0;
      char ch='a';
      cin>>t;
      char s[100][100];
      while(t--)
      {
          cin>>n;
          for(i=0;i<n;i++)
          {
              cin>>s[i];
          }
          for(i=0;i<(n-1);i++)
          {
              for(j=i+1;j<n;j++)
              {

                 for (int k=0,l = 0; l < 4; ++l,++k){
                    if(s[i][k] == s[j][l]){
                    ct++;
                    //cout<<"fuck"<<endl;
                  }

               }
               if(ct>=4)
               {
                   ck++;
                   s[j][e]='0'+f;
                   f++;
                   d++;
                   if(d>3)
                   {
                       e++;
                       d=0;
                   }
                   if(f>9)
                    f=0;
                   ct=0;
               }
               ct=0;
            }

          }
          cout<<ck<<endl;
          ck=0,f=0,d=0,e=0;
          //cout<<s[1][0];
          //s[100][100]={};
          for(i=0;i<n;i++)
          {
              for(j=0;j<4;j++)
              {
                  cout<<s[i][j];
              }
              cout<<endl;

          }

    }

	bye;

}

        /*Keep Me In Your Prayer*/


/*
       //......................................*
      //     Rudro Debnath                     *
      //     Dept Of CSE                       *
      //     University Of Barisal             *
      //****************************************
  _______________________________________________________
 /______GOD ______IS__________ALMIGHTY__________________/

 */

#include <bits/stdc++.h>
using namespace std;

#define inl(x) scanf("%lld",&x)
#define in(x)  scanf("%d",&x)
#define mxx 10000000000000
#define Y() cout<< "YES" <<endl
#define N() cout << "NO"<<endl
#define max_3(a,b,c) max(a, max(b,c))
#define max_4(a,b,c,d) max(a,max(b,max(c,d)))
#define min_3(a,b,c) min(a, min(b,c))
#define min_4(a,b,c,d) min(a,min(b,min(c,d)))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define bye return 0
#define ll long long
#define pi  2 * acos(0.0)
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{

	FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

      ll t,n,i,j,ct=0,ck=0,f=0;
      char ch='a';
      cin>>t;
      char s[100][100];
      while(t--)
      {
          cin>>n;
          for(i=0;i<n;i++)
          {
              cin>>s[i];
          }
          for(i=0;i<(n-1);i++)
          {
              for(j=i+1;j<n;j++)
              {

                 for (int k=0,l = 0; l < 4; ++l,++k){
                    if(s[i][k] == s[j][l]){
                    ct++;
                    //cout<<"fuck"<<endl;
                  }

               }
               if(ct>=4)
               {
                   ck++;
                   s[j][3]='0'+f;
                   f++;
                   if(f>9)
                    f=0;
                   ct=0;
               }
               ct=0;
            }

          }
          cout<<ck<<endl;
          ck=0;
          //cout<<s[1][0];
          //s[100][100]={};
          for(i=0;i<n;i++)
          {
              for(j=0;j<4;j++)
              {
                  cout<<s[i][j];
              }
              cout<<endl;

          }

    }

	bye;

}

        /*Keep Me In Your Prayer*/


/*
       //......................................*
      //     Rudro Debnath                     *
      //     Dept Of CSE                       *
      //     University Of Barisal             *
      //****************************************
  _______________________________________________________
 /______GOD ______IS__________ALMIGHTY__________________/

 */

#include <bits/stdc++.h>
using namespace std;

#define inl(x) scanf("%lld",&x)
#define in(x)  scanf("%d",&x)
#define mxx 10000000000000
#define Y() cout<< "YES" <<endl
#define N() cout << "NO"<<endl
#define max_3(a,b,c) max(a, max(b,c))
#define max_4(a,b,c,d) max(a,max(b,max(c,d)))
#define min_3(a,b,c) min(a, min(b,c))
#define min_4(a,b,c,d) min(a,min(b,min(c,d)))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define bye return 0
#define ll long long
#define pi  2 * acos(0.0)
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{

	FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

      ll t,n,i,j,ct=0,ck=0,f=1;
      char ch='a';
      cin>>t;
      char s[100][100];
      while(t--)
      {
          cin>>n;
          for(i=0;i<n;i++)
          {
              cin>>s[i];
          }
          for(i=0;i<(n-1);i++)
          {
              for(j=i+1;j<n;j++)
              {

                 for (int k=0,l = 0; l < 4; ++l,++k){
                    if(s[i][k] == s[j][l]){
                    ct++;
                    //cout<<"fuck"<<endl;
                  }

               }
               if(ct>=4)
               {
                   ck++;
                   s[j][0]='2';
                   f++;
                   ct=0;
               }
               ct=0;
            }

          }
          cout<<ck<<endl;
          ck=0;
          //cout<<s[1][0];
          //s[100][100]={};
          for(i=0;i<n;i++)
          {
              cout<<s[i]<<endl;
          }

    }

	bye;

}

        /*Keep Me In Your Prayer*/


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;

int main()
{
    ll T ; cin>>T ;

     while(T--)
    {
      ll N, cnt=0LL ; cin>>N ;
      map<string, queue<ll> > posns_of ;
      vector<string> ans(N, "") ;
      vector<string> pins(N, "") ;
      set<string> st ;

      for(ll i=0 ; i < N  ; i++)
      {
           cin>>pins[i] ;
           cin.ignore('\n', 10) ;
           if( posns_of.find(pins[i]) == posns_of.end() )
               posns_of[ pins[i] ] = queue<ll>() ;

           queue<ll> &posns = posns_of[ pins[i] ];
           posns.push(i) ;
      }

      for(auto it=posns_of.begin() ; it != posns_of.end() ; it++ )
      {
           string pin = it->first ;
           queue<ll> &posns = it->second ;
           st.insert(pin) ;
           ans[ posns.front() ] = it->first ;
           posns.pop() ;

           for(ll i=0 ; i < 4 &&  posns.size() > 0 ; i++ )
             for(char ch = '0' ; ch <= '9' && posns.size() > 0; ch++ )
              {
                   pin[i] = ch ;
                   if( st.find(pin) == st.end() )
                   {
                       st.insert(pin) ;
                       ans[ posns.front() ] = pin ;
                       posns.pop() ;
                       cnt++ ;
                       //cout << pin << ':' << cnt << '\n' ;
                   }
                   pin = it->first;
              }
      }

      cout << cnt << '\n' ;
      for(ll i=0; i<N; i++)
          cout << ans[i] << '\n' ;

    }

  return 0 ;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll ;

int main() {

    ll T ; cin>>T ;

    while(  T-- )
    {
       ll n ; cin>>n ;
       map<ll, ll> mp , imp ;
       vector<ll> v;

       for(ll i=0 ; i < n ; i++)
       {
           ll x ; cin>>x ;
           if( mp.find(x) != mp.end() )
                  mp[x]++ ;
           else
                  mp[x] = 1 ;
       }

       ll ans=0;
       for( auto it = mp.begin() ; it != mp.end() ; it++)
       {
           ans += (it->second) ; ans-- ;
           ll x = it->first ;
           ll cnt = it->second;

           if( cnt > 1)
               v.push_back(x) ;

               for(ll t = 0 ; t <= 9 && cnt > 1 ; t++, --cnt)
                  if( imp.find(x - (x%10) + t) == imp.end() )
                   v.push_back(x - (x%10) + t ) ;

       }

       cout << ans << '\n' ;
       for(ll i=0 ; i < v.size() ; i++)
       {
           ll x = v[i] ;
           stack<int> st ;
           for(ll j=0 ; j < 4 ; j++, x /= 10 )
                st.push(x%10 ) ;

            while( !st.empty() )
               { cout << st.top()    ; st.pop() ; }
            cout << '\n' ;
       }

    }

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll ;

int main() {

    ll T ; cin>>T ;

    while(  T-- )
    {
       ll n ; cin>>n ;
       map<ll, ll> mp , imp, inmp ;
       vector<ll> pos[10000], v(n, -1LL) ;

       for(ll i=0 ; i < n ; i++)
       {
           ll x ; cin>>x ;
           pos[x].push_back(i) ;

           if( mp.find(x) != mp.end() )
                  mp[x]++ ;
           else
                  mp[x] = 1 ;
       }

       ll ans=0;
       for( auto it = mp.begin() ; it != mp.end() ; it++)
       {
           ans += (it->second) ; ans-- ;
           ll x = it->first ;
           ll cnt = it->second;

               ll z= pos[x].back() ;
               pos[x].pop_back() ;
               v[z] = x ;

               for(ll t = 0 ; t <= 9 && cnt > 1 ; t++, --cnt)
                  if( imp.find(x - (x%10) + t) == imp.end() )
                     {
                         ll z= pos[x].back() ;
                         pos[x].pop_back() ;
                         v[z] = (x - (x%10) + t) ;
                     }

       }

       cout << ans << '\n' ;
       for(ll i=0 ; i < v.size() ; i++)
       {
           ll x = v[i] ;
           stack<int> st ;
           for(ll j=0 ; j < 4 ; j++, x /= 10 )
                st.push(x%10 ) ;

            while( !st.empty() )
               { cout << st.top()    ; st.pop() ; }
            cout << '\n' ;
       }

    }

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll ;

int main() {

    ll T ; cin>>T ;

    while(  T-- )
    {
       ll n ; cin>>n ;
       map<ll, ll> mp , imp, inmp ;
       vector<ll> pos[10000], v(n, -1LL) ;

       for(ll i=0 ; i < n ; i++)
       {
           ll x ; cin>>x ;
           pos[x].push_back(i) ;

           if( mp.find(x) != mp.end() )
                  mp[x]++ ;
           else
                  mp[x] = 1 ;
       }

       ll ans=0;
       for( auto it = mp.begin() ; it != mp.end() ; it++)
       {
           ans += (it->second) ; ans-- ;
           ll x = it->first ;
           ll cnt = it->second;

               ll z= pos[x].back() ;
               pos[x].pop_back() ;
               v[z] = x ;
               imp[x]=1;

               for(ll t = 0 ; t <= 9 && cnt > 1 ; t++)
                  if( imp.find(x - (x%10) + t) == imp.end() && mp.find(x - (x%10) + t) == mp.end() )
                     {
                         ll z= pos[x].back() ;
                         pos[x].pop_back() ;
                         v[z] = (x - (x%10) + t) ;
                         --cnt;
                         //cout << t << '*' << '\n' ;
                     }

       }

       cout << ans << '\n' ;
       for(ll i=0 ; i < v.size() ; i++)
       {
           ll x = v[i] ;
           stack<int> st ;
           for(ll j=0 ; j < 4 ; j++, x /= 10 )
                st.push(x%10 ) ;

            while( !st.empty() )
               { cout << st.top()    ; st.pop() ; }
            cout << '\n' ;
       }

    }

	return 0;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;

int main()
{
    ll T ; cin>>T ;

     while(T--)
    {
      ll N, cnt=0LL ; cin>>N ;
      map<string, queue<ll> > posns_of ;
      vector<string> ans(N, "") ;
      vector<string> pins(N, "") ;
      set<string> st ;

      for(ll i=0 ; i < N  ; i++)
      {
           cin>>pins[i] ;
           cin.ignore('\n', 10) ;
           if( posns_of.find(pins[i]) == posns_of.end() )
               posns_of[ pins[i] ] = queue<ll>() ;

           queue<ll> &posns = posns_of[ pins[i] ];
           posns.push(i) ;
      }

      for(auto it=posns_of.begin() ; it != posns_of.end() ; it++ )
      {
           string pin = it->first ;
           queue<ll> &posns = it->second ;
           st.insert(pin) ;
           ans[ posns.front() ] = it->first ;
           posns.pop() ;

           for(ll i=0 ; i < 4 &&  posns.size() > 0 ; i++ )
             for(char ch = '0' ; ch <= '9' && posns.size() > 0; ch++ )
              {
                   pin[i] = ch ;
                   if( st.find(pin) == st.end() && posns_of.find(pin) == posns_of.end() )
                   {
                       st.insert(pin) ;
                       ans[ posns.front() ] = pin ;
                       posns.pop() ;
                       cnt++ ;
                   }
                   pin = it->first;
              }
      }

      cout << cnt << '\n' ;
      for(ll i=0; i<N; i++)
          cout << ans[i] << '\n' ;

    }

  return 0 ;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll ;

int main() {

    ll T ; cin>>T ;

    while(  T-- )
    {
       ll n ; cin>>n ;
       map<ll, ll> mp , imp ;
       vector<ll> v;

       for(ll i=0 ; i < n ; i++)
       {
           ll x ; cin>>x ;
           if( mp.find(x) != mp.end() )
                  mp[x]++ ;
           else
                  mp[x] = 1 ;
       }

       ll ans=0;
       for( auto it = mp.begin() ; it != mp.end() ; it++)
       {
           ans += (it->second) ; ans-- ;
           ll x = it->first ;
           ll cnt = it->second;

               v.push_back(x) ;

               for(ll t = 0 ; t <= 9 && cnt > 1 ; t++, --cnt)
                  if( imp.find(x - (x%10) + t) == imp.end() )
                   v.push_back(x - (x%10) + t ) ;

       }

       cout << ans << '\n' ;
       for(ll i=0 ; i < v.size() ; i++)
       {
           ll x = v[i] ;
           stack<int> st ;
           for(ll j=0 ; j < 4 ; j++, x /= 10 )
                st.push(x%10 ) ;

            while( !st.empty() )
               { cout << st.top()    ; st.pop() ; }
            cout << '\n' ;
       }

    }

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll ;

int main() {

    ll T ; cin>>T ;

    while(  T-- )
    {
       ll n ; cin>>n ;
       map<ll, ll> mp , imp ;
       vector<ll> v;

       for(ll i=0 ; i < n ; i++)
       {
           ll x ; cin>>x ;
           if( mp.find(x) != mp.end() )
                  mp[x]++ ;
           else
                  mp[x] = 1 ;
       }

       ll ans=0;
       for( auto it = mp.begin() ; it != mp.end() ; it++)
       {
           ans += (it->second) ; ans-- ;
           ll x = it->first ;
           ll cnt = it->second;

           if( cnt > 1)
               v.push_back(x) ;

               for(ll t = 0 ; t <= 9 && cnt > 1 ; t++, --cnt)
                  if( imp.find(x - (x%10) + t) == imp.end() )
                   v.push_back(x - (x%10) + t ) ;

       }

       cout << ans << '\n' ;
       if(ans)
       for(ll i=0 ; i < v.size() ; i++)
       {
           ll x = v[i] ;
           stack<int> st ;
           for(ll j=0 ; j < 4 ; j++, x /= 10 )
                st.push(x%10 ) ;

            while( !st.empty() )
               { cout << st.top()    ; st.pop() ; }
            cout << '\n' ;
       }

    }

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll ;

int main() {

    ll T ; cin>>T ;

    while(  T-- )
    {
       ll n ; cin>>n ;
       map<ll, ll> mp , imp, inmp ;
       vector<ll> v(n, -1LL);

       for(ll i=0 ; i < n ; i++)
       {
           ll x ; cin>>x ;

           if(inmp.find(x) == inmp.end() )
              inmp[x] = i ;

           if( mp.find(x) != mp.end() )
                  mp[x]++ ;
           else
                  mp[x] = 1 ;
       }

       ll ans=0;
       for( auto it = mp.begin() ; it != mp.end() ; it++)
       {
           ans += (it->second) ; ans-- ;
           ll x = it->first ;
           ll cnt = it->second;

               ll z= inmp[x] ;
               v[z]=x;

               for(ll t = 0 ; t <= 9 && cnt > 1 ; t++, --cnt)
                  if( imp.find(x - (x%10) + t) == imp.end() )
                      v[++z] = (x - (x%10) + t) ;

       }

       cout << ans << '\n' ;
       for(ll i=0 ; i < v.size() ; i++)
       {
           ll x = v[i] ;
           stack<int> st ;
           for(ll j=0 ; j < 4 ; j++, x /= 10 )
                st.push(x%10 ) ;

            while( !st.empty() )
               { cout << st.top()    ; st.pop() ; }
            cout << '\n' ;
       }

    }

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll ;

int main() {

    ll T ; cin>>T ;

    while(  T-- )
    {
       ll n ; cin>>n ;
       map<ll, ll> mp , imp, inmp ;
       vector<ll> pos[10000], v(n, -1LL) ;

       for(ll i=0 ; i < n ; i++)
       {
           ll x ; cin>>x ;
           pos[x].push_back(i) ;

           if( mp.find(x) != mp.end() )
                  mp[x]++ ;
           else
                  mp[x] = 1 ;
       }

       ll ans=0;
       for( auto it = mp.begin() ; it != mp.end() ; it++)
       {
           ans += (it->second) ; ans-- ;
           ll x = it->first ;
           ll cnt = it->second;

               ll z= pos[x].back() ;
               pos[x].pop_back() ;
               v[z] = x ;
               imp[x]=1;

               for(ll t = 0 ; t <= 9 && cnt > 1 ; t++)
                  if( imp.find(x - (x%10) + t) == imp.end() )
                     {
                         ll z= pos[x].back() ;
                         pos[x].pop_back() ;
                         v[z] = (x - (x%10) + t) ;
                         --cnt;
                         //cout << t << '*' << '\n' ;
                     }

       }

       cout << ans << '\n' ;
       for(ll i=0 ; i < v.size() ; i++)
       {
           ll x = v[i] ;
           stack<int> st ;
           for(ll j=0 ; j < 4 ; j++, x /= 10 )
                st.push(x%10 ) ;

            while( !st.empty() )
               { cout << st.top()    ; st.pop() ; }
            cout << '\n' ;
       }

    }

	return 0;
}


import java.util.Arrays;
import java.util.Scanner;
public class Ayush {
public static void main(String [] args){
	Scanner s=new Scanner(System.in);
	int t=s.nextInt();
	while(t-->0){
	  String st=s.next();
	  String[]str=st.split("0+");
	  int x=0;
	  Arrays.sort(str);
	  for(int j=str.length-1;j>=0;j-=2) {

				x+=str[j].length();
			}
			System.out.println(x);

	}}

		}


import java.util.*;
public class codeforces
{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int t=sc.nextInt();
    while(t-- >0)
    {
      int c=0,sum=0;
      String b=sc.next();
      int n=b.length();
      ArrayList<Integer> v=new  ArrayList<>();
      for(int i=0;i<n;i++)
      {
        char ch=b.charAt(i);
        if(ch=='1')
        c++;
        else
        {
          if(c>0)
          v.add(c);
          c=0;
        }
      }
      if(c>0)
      v.add(c);
      Collections.sort(v);
      Collections.reverse(v);
      for(int i=0;i<v.size();i+=2)
      {
        sum+=(int)v.get(i);
      }
      System.out.println(sum);
    }

  }
}


import java.util.*;
public class P1398B
{

  public static void main(String args[])
  {

    Scanner in = new Scanner(System.in);
    int t = in.nextInt();
    while(t-->0)
    {

      StringBuilder s = new StringBuilder(in.next());
      int len = s.length();

      ArrayList<Integer> pref = new ArrayList<Integer>();
      pref.add(s.charAt(0) - '0');

      for(int i=1;i<len;++i)
      {
          if(s.charAt(i)!='0')
          {
            pref.add(pref.get(i-1) + s.charAt(i) - '0');
            pref.set(i-1,0);
          }
          else
          {
            pref.add(0);
          }
      }

      Collections.sort(pref);

      int ans = 0;
      for(int i=len-1;(i>=0&&pref.get(i)!=0);i-=2)
      {
        ans += pref.get(i);
      }
      System.out.println(ans);
    }
  }
}


import java.util.*;
public class P1398B
{

  public static void main(String args[])
  {

    Scanner in = new Scanner(System.in);
    int t = in.nextInt();
    while(t-->0)
    {

      StringBuilder s = new StringBuilder(in.next());
      int len = s.length();

      ArrayList<Integer> pref = new ArrayList<Integer>();
      pref.add(s.charAt(0) - '0');

      for(int i=1;i<len;++i)
      {
          if(s.charAt(i)!='0')
          {
            pref.add(pref.get(i-1) + s.charAt(i) - '0');
            pref.set(i-1,0);
          }
          else
          {
            pref.add(0);
          }
      }

      Collections.sort(pref);

      int ans = 0;
      for(int i=len-1;(pref.get(i)!=0&&i>=0);i-=2)
      {
        ans += pref.get(i);
      }
      System.out.println(ans);
    }
  }
}


import java.util.*;
import java.io.*;

public class Ideone{
	static class Reader{
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
	static int score(String s){
		String[] S=s.split("[0]+");
		int len=S.length;
		int[] num=new int[len];
		for(int i=0;i<len;i++){
			num[i]=S[i].length();
		}
		Arrays.sort(num);
		int sum=0;
		for(int i=len-1;i>-1;i-=2){
			sum+=num[i];
		}
		return sum;
	}
	public static void main (String[] args) throws java.lang.Exception{
		Reader sc=new Reader();
		int t=sc.nextInt();
		while(t--!=0)
			System.out.println(score(sc.readLine()));
	}
}


import java.util.*;
import java.lang.*;
import java.io.*;

public class Ideone{
	static int score(String s){
		String[] S=s.split("[0]+");
		int len=S.length;
		int[] num=new int[len];
		for(int i=0;i<len;i++){
			num[i]=S[i].length();
		}
		Arrays.sort(num);
		int sum=0;
		for(int i=len-1;i>-1;i-=2){
			sum+=num[i];
		}
		return sum;
	}
	public static void main (String[] args) throws java.lang.Exception{
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t--!=0)
			System.out.println(score(sc.next()));
	}
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class B {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int T = sc.nextInt();
        sc.nextLine();

        for(int t = 0; t < T; t++){

            String s = sc.nextLine();

            ArrayList<Integer> ones = new ArrayList<>();

            int countOnes = 0;

            for(int i = 0; i < s.length(); i++){

                if (s.charAt(i) == '0'){
                    if (countOnes > 0) {
                        ones.add(countOnes);
                        countOnes = 0;
                    }
                }
                else{
                    countOnes++;
                }

            }

            if (countOnes > 0) ones.add(countOnes);

            Collections.sort(ones);

            int ans = 0;

            for(int i = ones.size() - 1; i >= 0; i-=2){
                ans += ones.get(i);
            }

            System.out.println(ans);
        }
    }
}


import java.util.*;
import java.io.*;
import org.apache.commons.lang3.StringUtils;
public class SRemoval
{
  public static void main(String[] args)throws Exception
  {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int t=Integer.parseInt(br.readLine());

    for(int u=0;u<t;u++)
    {
      String s= br.readLine();
      String str = StringUtils.repeat('1',s.length());int alice=0;int bob=0;int turn=0;
      while(s.contains("1"))
      {
        while(s.contains(str))
        {
            if(turn==0)
            {
              alice+=str.length();
              StringUtils.replaceOnce(s, str, "");
              turn=1;
            }
            else
            {
              bob+=str.length();
              StringUtils.replaceOnce(s, str, "");
              turn=0;
            }
        }
      }
      System.out.println(alice);
    }
  }
}


import java.util.*;
import java.io.*;
public class SRemoval
{
  public static void main(String[] args)throws Exception
  {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int t=Integer.parseInt(br.readLine());
    for(int u=0;u<t;u++)
    {
      String s= br.readLine();
      int n=s.length();
      String str="1";int alice=0,bob=0;int turn=0;
      for(int i=1;i<n;i++)
        str+="1";
      while(s.contains("1"))
      {
        while(s.contains(str))
        {
            if(turn==0)
            {
              alice+=str.length();
              s=s.replaceFirst(str,"");
              turn=1;
            }
            else
            {
              bob+=str.length();
              s=s.replaceFirst(str,"");
              turn=0;
            }
        }
          str = str.substring(0, str.length() - 1);
      }
      System.out.println(alice);
    }
  }
}


import java.util.*;
import java.io.*;
public class Solution {

	static Scanner scr=new Scanner(System.in);
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int t=scr.nextInt();
		while(t-->0) {
			solve();
			System.out.println();
		}
	}
	static void solve() {
		String s=scr.next();
		s+=0;
		int n=s.length();
		int count=0;
		ArrayList<Integer>a=new ArrayList<Integer>();
		for(int i=0;i<n;i++) {
			if(s.charAt(i)=='1') {
				count++;
			}else if(s.charAt(i)=='0'){
				a.add(count);
				count=0;
			}
		}
		Collections.sort(a,new Comparator<Integer>() {

			@Override
			public int compare(Integer o1, Integer o2) {
				return o2-o1;
			}

		});
		int ans=0;
		for(int i=0;i<a.size();i+=2) {
			ans+=a.get(i);
		}
		System.out.print(ans);
	}
}


import java.util.*;
import java.io.*;
public class Solution {

	static Scanner scr=new Scanner(System.in);
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int t=scr.nextInt();
		while(t-->0) {
			solve();
			System.out.println();
		}
	}
	static void solve() {
		String s=scr.next();
		int n=s.length();
		int count=0;
		ArrayList<Integer>a=new ArrayList<Integer>();
		for(int i=0;i<n;i++) {
			if(s.charAt(i)=='1') {
				count++;
			}else if(s.charAt(i)=='0'){
				a.add(count);
				count=0;
			}
		}
		if(s.charAt(n-1)=='1') {
			a.add(count);
		}
		Collections.sort(a);
		int ans=0;
		for(int i=0;i<a.size();i+=2) {
			ans+=a.get(i);
		}
		System.out.print(ans);
	}
}


import java.util.*;
import java.io.*;
public class Solution {

	static Scanner scr=new Scanner(System.in);
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int t=scr.nextInt();
		while(t-->0) {
			solve();
			System.out.println();
		}
	}
	static void solve() {
		String s=scr.next();
		s+=0;
		int n=s.length();
		int count=0;
		ArrayList<Integer>a=new ArrayList<Integer>();
		for(int i=0;i<n;i++) {
			if(s.charAt(i)=='1') {
				count++;
			}else if(s.charAt(i)=='0'){
				a.add(count);
				count=0;
			}
		}
		Collections.sort(a);
		int ans=0;
		for(int i=0;i<a.size();i+=2) {
			ans+=a.get(i);
		}
		System.out.print(ans);
	}
}


import java.util.*;
public class Solution{
	public static void main(String args[])
	{
		Scanner take=new Scanner(System.in);
		ArrayList<Integer> a=new ArrayList<>();
		int t=take.nextInt();
		String s;
		int n,i,c,flag;
		while(t--!=0)
		{	a.clear();
			s=take.next();
			n=s.length();
			c=0;
			for(i=0;i<n;i++)
			{	c=0;
				flag=0;
				while(i<n&&s.charAt(i)=='1')
				{
					c++;
					i++;
					flag=1;
				}
				//a.add(c);
				if(flag==1)
				{
					i--;
					a.add(c);
				}

			}
			Collections.sort(a);
			//System.out.println(a);
			int ans=0;
			for(i=a.size()-1;i>=0;i-=2)
			{
				ans+=a.get(i);
			}
			System.out.println(ans);
		}

	}
}


import java.io.*;
    import java.util.*;
    import java.text.*;
    import java.math.*;
    import java.util.regex.*;

   public class Solution {

        public static void main(String[] args) {
            Scanner scan=new Scanner(System.in);

               int t=scan.nextInt();
            while(t-->0)
            {
                String s=scan.next();
                int c0=0;
                int c1=1;
                List<Integer> ls=new ArrayList();

                for(int i=1;i<s.length();i++)
                {
                    if(s.charAt(i)=='1'&&s.charAt(i)==s.charAt(i-1))
                    {
                     c1++;
                    }else if(s.charAt(i-1)=='1')
                    {
                        ls.add(c1);
                        c1=1;
                    }
                }
                if(s.charAt(s.length()-1)=='1')
                {
                    ls.add(c1);
                }
                //System.out.println(ls);
                Collections.sort(ls);
                int ans=0;

                for(int i=ls.size()-1;i>=0;i=i-2)
                {
                    ans+=ls.get(i);
                }

                System.out.println(ans);

            }
        }
    }


import java.io.*;
    import java.util.*;
    import java.text.*;
    import java.math.*;
    import java.util.regex.*;

  public  class Solution {

        public static void main(String[] args) {
            Scanner scan=new Scanner(System.in);

               int t=scan.nextInt();
            while(t-->0)
            {
                String s=scan.next();
                int c0=0;
                int c1=0;

                for(int i=0;i<s.length();i++)
                {
                    if(s.charAt(i)=='0')
                    {
                        c0++;
                    }else
                    {
                        c1++;
                    }
                }

                if(c1<=c0)
                {
                    System.out.println(c1);
                }
                else{
                int ans=c0+(int)Math.ceil((double)(c1-c0)/2);

                    System.out.println(ans);
                    }

            }
        }
    }


import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
//        br = new BufferedReader(new FileReader(new File("subtract.in")));
//        out = new PrintWriter(new File("subtract.out"));
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        int PUTEN = nextInt();
        for (int POMOGI = 0; POMOGI < PUTEN; POMOGI++) {
            char[] p = next().toCharArray();
            int n = p.length;
            int ind = 0;
            ArrayList<Integer> popka = new ArrayList<>();
            while (ind < n) {
                int cnt = 0;
                while (ind != n && p[ind] == '1') {
                    cnt++;
                    ind++;
                }
                ind++;
                if (cnt != 0) popka.add(cnt);
            }
            Collections.sort(popka);
            n = popka.size();
            int ans = 0;
            for (int i = n - 1; i >= 0; i -= 2) {
                ans += popka.get(i);
            }
            out.println(ans);
        }
        out.close();
    }

    static BufferedReader br;
    static PrintWriter out;
    static StringTokenizer in = new StringTokenizer("");

    static String next() throws IOException {
        while (!in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

}


import java.util.*;
public class july2
{
    public static void main(String[]args)
    {
        Scanner in=new Scanner(System.in);
        int t=in.nextInt();
        for(int i=0;i<t;i++)
        {
            String s=in.next();s=s+'0';int[] arr=new int[101];int k=0,c=0;
            for(int j=0;j<s.length();j++)
            {
                if(s.charAt(j)=='1')
                {
                    c++;
                }
                else
                {
                    arr[k]=c;
                    c=0;
                    k++;
                }
            }
            Arrays.sort(arr);long ans=0;
            for(int j=100;j>=0;j++)
            {
                if(j%2==0)
                {
                    ans+=arr[j];
                }
            }
            System.out.println(ans);
        }
    }
}


import java.util.*;
public class july2
{
    public static void main(String[]args)
    {
        Scanner in=new Scanner(System.in);
        int t=in.nextInt();
        for(int i=0;i<t;i++)
        {
            String s=in.next();s=s+'0';int[] arr=new int[101];int k=0,c=0;
            for(int j=0;j<s.length();j++)
            {
                if(s.charAt(j)=='1')
                {
                    c++;
                }
                else
                {
                    arr[k]=c;
                    c=0;
                    k++;
                }
            }
            Arrays.sort(arr);long ans=0;
            for(int j=100;j>=0;j--)
            {
                if(j%2==0)
                {
                    ans+=arr[j];
                }
            }
            System.out.println(ans);
        }
    }
}


import java.util.*;
public class july2
{
    public static void main(String[]args)
    {
        Scanner in=new Scanner(System.in);
        int t=in.nextInt();
        for(int i=0;i<t;i++)
        {
            String s=in.next();s=s+'0';int[] arr=new int[101];int k=0,c=0;
            for(int j=0;j<s.length();j++)
            {
                if(s.charAt(j)==1)
                {
                    c++;
                }
                else
                {
                    arr[k]=c;
                    c=0;
                    k++;
                }
            }
            Arrays.sort(arr);long ans=0;
            for(int j=100;j>=0;j++)
            {
                if(j%2==0)
                {
                    ans+=arr[j];
                }
            }
            System.out.println(ans);
        }
    }
}


import java.util.*;
import java.io.*;
import java.lang.*;

public class Main
{
    public static int getMax(int arr[])
    {
        int n=arr.length;
        int i,j;
        int max=-1,index=0;
        for(i=0;i<n;i++)
        {
            if(arr[i]>max)
            {
                max=arr[i];
                index=i;
            }
        }
        arr[index]=-1;
        return max;
    }
    public static void main(String [] args)
    {
        Scanner input = new Scanner(System.in);
        int t,n,i,j;
        String str;
        t= input.nextInt();
        while(t-- >0)
        {
            str=input.next();
            n=str.length();
            Vector<Integer> vec = new Vector<>();
            i=0;int count=0;
            while(i<n)
            {
                if(str.charAt(i)=='1')
                count++;
                else
                {
                    vec.add(count);
                    count=0;
                }
                i++;
            }
            vec.add(count);
//            System.out.println(vec);
            int brr[]=new int[vec.size()];
            for(i=0;i<vec.size();i++)
            brr[i]=vec.get(i);
            int a=0,b=0;
            for(i=1;i<=vec.size();i++)
            {
                int result=getMax(brr);
                if(result==0)
                break;
                if(i%2==1)
                {
                    a+=result;
                }
            }
            System.out.println(a);
        }
    }
}


import java.util.*;
import java.io.*;
import java.lang.*;

public class Main{

    public static int getMaxLength(int arr[], int n)
    {

        int count = 0; //intitialize count
        int result = 0; //initialize max
        int i,j=0;
        int once=0;
        for(i=0;i<n;i++)
        {
            if(arr[i]==1)
            once++;
            else
            break;
        }
        for (i = 0; i < n; i++)
        {
            // Reset count when 0 is found

            if (arr[i] == 0)
            {
                count = 0;
            }

            // If 1 is found, increment count
            // and update result if count becomes
            // more.
            else
            {

                count++;//increase count
                if(result<count)
                {
                    result=count;
                    j=i;
                }
            }

        }
        if(once==j+1)
        {
            for(i=0;i<once;i++)
            arr[i]=0;
        }
        else
        for(i=(j-result);i<=j;i++)
        arr[i]=0;

        return result;
    }
    public static void main(String [] args)
    {
        Scanner input = new Scanner(System.in);
        int t,i,j;
        String str;
        t=input.nextInt();
        while(t-- >0)
        {
            str = input.next();
            int n=str.length();
            int arr[] =new int[n];
            for(i=0;i<n;i++)
            {
                if(str.charAt(i)=='0')
                arr[i]=0;
                else
                arr[i]=1;
            }
            int result=-1;
            int scoreA=0,scoreB=0;
            int loop=1;
            while(result!=0)
            {
                result= getMaxLength(arr,n);
                if(loop%2==1)
                scoreA +=result;
                else
                scoreB +=result;
                loop++;
            }
            System.out.println(scoreA);

        }
    }
}


/*
    Modassir_Ali
    algo.java
*/
import java.util.*;
import java.io.*;
import java.util.Stack ;
import java.util.HashSet;
import java.util.HashMap;

public class B_CF664
{
    static class FastReader
    {
            BufferedReader br;
            StringTokenizer st;

            public FastReader()
            {
                br = new BufferedReader(new InputStreamReader(System.in));
            }

            String next()
            {
                while (st == null || !st.hasMoreElements())
                {
                    try
                    {
                        st = new StringTokenizer(br.readLine());
                    }
                    catch (IOException  e)
                    {
                        e.printStackTrace();
                    }
                }
                return st.nextToken();
            }

            int nextInt()
            {
                return Integer.parseInt(next());
            }

            long nextLong()
            {
                return Long.parseLong(next());
            }

            double nextDouble()
            {
                return Double.parseDouble(next());
            }

            String nextLine()
            {
                String str = "";
                try
                {
                    str = br.readLine();
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
                return str;
            }
    }

    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static int[][] nai2(int n,int m)throws IOException{int a[][] = new int[n][m];for(int i=0;i<n;i++)for(int j=0;j<m;j++)a[i][j] = ni();return a;}
    static int[] nai(int N,int start)throws IOException{int[]A=new int[N+start];for(int i=start;i!=(N+start);i++){A[i]=ni();}return A;}
    static Integer[] naI(int N,int start)throws IOException{Integer[]A=new Integer[N+start];for(int i=start;i!=(N+start);i++){A[i]=ni();}return A;}
    static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
    static void print(int arr[]){for(int i=0;i<arr.length;i++)out.print(arr[i]+" ");out.println();}
    static void print(long arr[]){for(int i=0;i<arr.length;i++)out.print(arr[i]+" ");out.println();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));} // return the number of set bits.
    static boolean isPrime(int number){if(number==1) return false;if (number == 2 || number == 3){return true;}if (number % 2 == 0) {return false;}int sqrt = (int) Math.sqrt(number) + 1;for(int i = 3; i < sqrt; i += 2){if (number % i == 0){return false;}}return true;}
    static boolean isPrime(long number){if(number==1) return false;if (number == 2 || number == 3){return true;}if (number % 2 == 0) {return false;}long sqrt = (long) Math.sqrt(number) + 1;for(int i = 3; i < sqrt; i += 2){if (number % i == 0){return false;}}return true;}
    static int power(int n,int p){if(p==0)return 1;int a = power(n,p/2);a = a*a;int b = p & 1;if(b!=0){a =  n*a;}return a;}
    static long power(long n,long p){if(p==0)return 1;long a = power(n,p/2);a = a*a;long b = p & 1;if(b!=0){a =  n*a;}return a;}
    static void reverse(int[] a) {int b;for (int i = 0, j = a.length - 1; i < j; i++, j--) {b = a[i];a[i] = a[j];a[j] = b;}}
    static void reverse(long[] a) {long b;for (int i = 0, j = a.length - 1; i < j; i++, j--) {b = a[i];a[i] = a[j];a[j] = b;}}
    static void swap(int a[],int i,int j){a[i] = a[i] ^ a[j];a[j] = a[j] ^ a[i];a[i] = a[i] ^ a[j];}
    static void swap(long a[],int i,int j){a[i] = a[i] ^ a[j];a[j] = a[j] ^ a[i];a[i] = a[i] ^ a[j];}
    static int count(int n){int c=0;while(n>0){c++;n = n/10;}return c;}
    static int[] prefix_sum(int a[],int n){int s[] = new int[n];s[0] = a[0];for(int i=1;i<n;i++){s[i] = a[i]+s[i-1];}return s;}
    static long[] prefix_sum_int(int a[],int n){long s[] = new long[n];s[0] = (long)a[0];for(int i=1;i<n;i++){s[i] = ((long)a[i])+s[i-1];}return s;}
    static long[] prefix_sum_Integer(Integer a[],int n){long s[] = new long[n];s[0] = (long)a[0];for(int i=1;i<n;i++){s[i] = ((long)a[i])+s[i-1];}return s;}
    static long[] prefix_sum_long(long a[],int n){long s[] = new long[n];s[0] = a[0];for(int i=1;i<n;i++){s[i] = a[i]+s[i-1];}return s;}
    static boolean isPerfectSquare(double x){double sr = Math.sqrt(x);return ((sr - Math.floor(sr)) == 0);}
    static ArrayList<Integer> sieve(int n) {int k=0; boolean prime[] = new boolean[n+1];ArrayList<Integer> p_arr = new ArrayList<>();for(int i=0;i<n;i++) prime[i] = true;for(int p = 2; p*p <=n; p++){ k=p;if(prime[p] == true) { p_arr.add(p);for(int i = p*2; i <= n; i += p) prime[i] = false; } }for(int i = k+1;i<=n;i++){if(prime[i]==true)p_arr.add(i);}return p_arr;}
    static boolean[] seive_check(int n) {boolean prime[] = new boolean[n+1];for(int i=0;i<n;i++) prime[i] = true;for(int p = 2; p*p <=n; p++){ if(prime[p] == true) { for(int i = p*2; i <= n; i += p) prime[i] = false; } }prime[1]=false;return prime;}
    static int get_bits(int n){int p=0;while(n>0){p++;n = n>>1;}return p;}
    static int get_bits(long n){int p=0;while(n>0){p++;n = n>>1;}return p;}
    static int get_2_power(int n){if((n & (n-1))==0)return get_bits(n)-1;return -1;}
    static int get_2_power(long n){if((n & (n-1))==0)return get_bits(n)-1;return -1;}
    static void close(){out.flush();}

    /*-------------------------Main Code Starts(algo.java)----------------------------------*/
public static void main(String[] args) throws IOException {
    int  n = ni() ;
    int  m = ni() ;
    int  x = ni() ;
    int  y = ni() ;
    HashSet<String> set = new LinkedHashSet<String>() ;
    set.add(x+" "+y) ;
    for(int i=1 ; i<=m ; i++){
        if(!set.contains(x+" "+i)){
            set.add(x+" "+i) ;
        }
    }

    // System.out.println(set);
   if(x%2==0){
       for(int i=x+1 ; i<=n ; i++){
           if(i%2==0){
                set.addAll(straight(i, m)) ;
           }
           else{
               set.addAll(reverse(i, m)) ;
           }
       }
   }
   else{
    for(int i=x+1 ; i<=n ; i++){
        if(i%2!=0){
             set.addAll(straight(i, m)) ;
        }
        else{
            set.addAll(reverse(i, m)) ;
        }

    }
   }

   set.addAll(rest(x, m,n)) ;
//    int b=0 ;
   for(String b : set) {
      System.out.println(b);
   }
}

static LinkedHashSet<String> reverse(int i , int start){
    LinkedHashSet<String> set = new LinkedHashSet<String>() ;
    for(int j = start ; j>=1 ; j--){
        set.add(i+" "+j) ;
    }
    return set ;
}

static LinkedHashSet<String> straight(int i , int end){
    LinkedHashSet<String> set = new LinkedHashSet<String>() ;
    for(int j = 1 ; j<=end ; j++){
        set.add(i+" "+j) ;
    }
    return set ;
}

static LinkedHashSet<String> rest(int x , int end,int n){
    LinkedHashSet<String> set = new LinkedHashSet<String>() ;
    if((x%2==0 && n%2==0) || (x%2!=0 && n%2!=0)){
       for(int i = x-1 ; i>=1 ; i--){
           if((x-1)%2!=0){
               if(i%2!=0){
                   set.addAll(reverse(i, end)) ;
               }
               else{
                   set.addAll(straight(i, end)) ;
               }
           }
           else{
            if(i%2==0){
                set.addAll(reverse(i, end)) ;
            }
            else{
                set.addAll(straight(i, end)) ;
            }

           }
       }
    }
    else{
        for(int i = x-1 ; i>=1 ; i--){
            if((x-1)%2!=0){
                if(i%2!=0){
                    set.addAll(straight(i, end)) ;
                }
                else{
                    set.addAll(reverse(i, end)) ;
                }
            }
            else{
             if(i%2==0){
                 set.addAll(straight(i, end)) ;
             }
             else{
                 set.addAll(reverse(i, end)) ;
             }

            }
        }
    }
    return set ;
}

}


/*
    Modassir_Ali
    algo.java
*/
import java.util.*;
import java.io.*;
import java.util.Stack ;
import java.util.HashSet;
import java.util.HashMap;

public class B_Round93CF
{
    static class FastReader
    {
            BufferedReader br;
            StringTokenizer st;

            public FastReader()
            {
                br = new BufferedReader(new InputStreamReader(System.in));
            }

            String next()
            {
                while (st == null || !st.hasMoreElements())
                {
                    try
                    {
                        st = new StringTokenizer(br.readLine());
                    }
                    catch (IOException  e)
                    {
                        e.printStackTrace();
                    }
                }
                return st.nextToken();
            }

            int nextInt()
            {
                return Integer.parseInt(next());
            }

            long nextLong()
            {
                return Long.parseLong(next());
            }

            double nextDouble()
            {
                return Double.parseDouble(next());
            }

            String nextLine()
            {
                String str = "";
                try
                {
                    str = br.readLine();
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
                return str;
            }
    }

    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static int[][] nai2(int n,int m)throws IOException{int a[][] = new int[n][m];for(int i=0;i<n;i++)for(int j=0;j<m;j++)a[i][j] = ni();return a;}
    static int[] nai(int N,int start)throws IOException{int[]A=new int[N+start];for(int i=start;i!=(N+start);i++){A[i]=ni();}return A;}
    static Integer[] naI(int N,int start)throws IOException{Integer[]A=new Integer[N+start];for(int i=start;i!=(N+start);i++){A[i]=ni();}return A;}
    static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
    static void print(int arr[]){for(int i=0;i<arr.length;i++)out.print(arr[i]+" ");out.println();}
    static void print(long arr[]){for(int i=0;i<arr.length;i++)out.print(arr[i]+" ");out.println();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));} // return the number of set bits.
    static boolean isPrime(int number){if(number==1) return false;if (number == 2 || number == 3){return true;}if (number % 2 == 0) {return false;}int sqrt = (int) Math.sqrt(number) + 1;for(int i = 3; i < sqrt; i += 2){if (number % i == 0){return false;}}return true;}
    static boolean isPrime(long number){if(number==1) return false;if (number == 2 || number == 3){return true;}if (number % 2 == 0) {return false;}long sqrt = (long) Math.sqrt(number) + 1;for(int i = 3; i < sqrt; i += 2){if (number % i == 0){return false;}}return true;}
    static int power(int n,int p){if(p==0)return 1;int a = power(n,p/2);a = a*a;int b = p & 1;if(b!=0){a =  n*a;}return a;}
    static long power(long n,long p){if(p==0)return 1;long a = power(n,p/2);a = a*a;long b = p & 1;if(b!=0){a =  n*a;}return a;}
    static void reverse(int[] a) {int b;for (int i = 0, j = a.length - 1; i < j; i++, j--) {b = a[i];a[i] = a[j];a[j] = b;}}
    static void reverse(long[] a) {long b;for (int i = 0, j = a.length - 1; i < j; i++, j--) {b = a[i];a[i] = a[j];a[j] = b;}}
    static void swap(int a[],int i,int j){a[i] = a[i] ^ a[j];a[j] = a[j] ^ a[i];a[i] = a[i] ^ a[j];}
    static void swap(long a[],int i,int j){a[i] = a[i] ^ a[j];a[j] = a[j] ^ a[i];a[i] = a[i] ^ a[j];}
    static int count(int n){int c=0;while(n>0){c++;n = n/10;}return c;}
    static int[] prefix_sum(int a[],int n){int s[] = new int[n];s[0] = a[0];for(int i=1;i<n;i++){s[i] = a[i]+s[i-1];}return s;}
    static long[] prefix_sum_int(int a[],int n){long s[] = new long[n];s[0] = (long)a[0];for(int i=1;i<n;i++){s[i] = ((long)a[i])+s[i-1];}return s;}
    static long[] prefix_sum_Integer(Integer a[],int n){long s[] = new long[n];s[0] = (long)a[0];for(int i=1;i<n;i++){s[i] = ((long)a[i])+s[i-1];}return s;}
    static long[] prefix_sum_long(long a[],int n){long s[] = new long[n];s[0] = a[0];for(int i=1;i<n;i++){s[i] = a[i]+s[i-1];}return s;}
    static boolean isPerfectSquare(double x){double sr = Math.sqrt(x);return ((sr - Math.floor(sr)) == 0);}
    static ArrayList<Integer> sieve(int n) {int k=0; boolean prime[] = new boolean[n+1];ArrayList<Integer> p_arr = new ArrayList<>();for(int i=0;i<n;i++) prime[i] = true;for(int p = 2; p*p <=n; p++){ k=p;if(prime[p] == true) { p_arr.add(p);for(int i = p*2; i <= n; i += p) prime[i] = false; } }for(int i = k+1;i<=n;i++){if(prime[i]==true)p_arr.add(i);}return p_arr;}
    static boolean[] seive_check(int n) {boolean prime[] = new boolean[n+1];for(int i=0;i<n;i++) prime[i] = true;for(int p = 2; p*p <=n; p++){ if(prime[p] == true) { for(int i = p*2; i <= n; i += p) prime[i] = false; } }prime[1]=false;return prime;}
    static int get_bits(int n){int p=0;while(n>0){p++;n = n>>1;}return p;}
    static int get_bits(long n){int p=0;while(n>0){p++;n = n>>1;}return p;}
    static int get_2_power(int n){if((n & (n-1))==0)return get_bits(n)-1;return -1;}
    static int get_2_power(long n){if((n & (n-1))==0)return get_bits(n)-1;return -1;}
    static void close(){out.flush();}

    /*-------------------------Main Code Starts(algo.java)----------------------------------*/
public static void main(String[] args) throws IOException {
    // BufferedReader br  = new BufferedReader(new InputStreamReader(System.in)) ;
    // int t = Integer.parseInt(br.readLine()) ;
    int t = ni() ;
    while(t--!=0){
        String str = sc.next() ;
        char ch[] = str.toCharArray();
        int n = frequency(ch) ;
        if(n==-1){
            System.out.println(0);
            continue ;
        }
        String one  = "1" ;
        int flag = 0 ;
        int count  = 0 ;
        int i = 0 ;
        for(i=n ; i>=1 ; i--){
           while(str.contains(one.repeat(i))){
            if(str.contains(one.repeat(i))){
                str = str.replaceFirst(one.repeat(i), "") ;
                if(flag%2==0){
                    count = count + i ;
                }
                flag++ ;
            }
           }

        }
      System.out.println(count);
    }
}

static int frequency(char ch[]){
    HashMap<Character,Integer> map = new HashMap<>() ;
    for(char x : ch){
        Integer count = map.get(x) ;
        if(count==null){
            map.put(x,1) ;
        }
        else{
            count++ ;
            map.put(x, count) ;
        }
    }
    if(map.get('1')==null){
        return -1 ;
    }
      return map.get('1') ;
    }
}


import java.util.*;
import java.io.*;

public class SubstringRemoval {
    public static void main (String[] args){
        Scanner scan = new Scanner(System.in);
        int T = scan.nextInt();

        for(int i=0; i<T; i++) {
            String input = scan.next();
            int[] lenOfOnes = new int[input.length()];
            int oneIndex = 0;
            int strIndex = 0;
            int curLen = 0;
            while(strIndex<input.length()){
                if(input.charAt(strIndex)=='0'){
                    lenOfOnes[oneIndex] = curLen;
                    oneIndex++;
                    curLen = 0;
                }
                else{
                    curLen++;
                    if(strIndex==input.length()-1){
                        lenOfOnes[oneIndex] = curLen;
                    }
                }
                strIndex++;
            }
            Arrays.sort(lenOfOnes);
            // System.out.println(Arrays.toString(lenOfOnes));

            int aliceTotal = 0;

            for(int j=lenOfOnes.length-1; j>=0 && lenOfOnes[j]!=0; j=j-2) {
                aliceTotal += lenOfOnes[j];
            }

            System.out.println(aliceTotal);
        }

    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

public class SubstringRemovalGame {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int tests = sc.nextInt();
		for(int t=0; t<tests; t++) {

			String str = sc.next();
			HashMap<Integer,Integer> map = new HashMap<>();
			ArrayList<Integer> arr = new ArrayList<>();
			int count = 0;
			int total_moves = 0;
			for(int i=0; i<str.length(); i++) {
				if(str.charAt(i)=='0' && count>0) {
					//System.out.print(count+" ");
					if(map.containsKey(count)) {
						map.put(count,map.get(count)+1);
					}
					else {
						map.put(count,1);
						arr.add(count);
					}
					total_moves++;
					count=0;
				}
				else if(str.charAt(i)=='1'){
					count++;
				}
			}
			if(count>0) {
				//System.out.print(count+" ");
				if(map.containsKey(count)) {
					map.put(count,map.get(count)+1);
				}
				else {
					map.put(count,1);
					arr.add(count);
				}
				total_moves++;
			}

			int score1 = 0;
			int score2 = 0;
			boolean flag = true;
			Collections.sort(arr);

			for(int i=arr.size()-1; i>=0 && total_moves>0; i--) {
				if(flag) {
					score1 += arr.get(i)*((Math.min(map.get(arr.get(i)),total_moves)+1)/2);
					score2 += arr.get(i)*((Math.min(map.get(arr.get(i)),total_moves)/2));
				}
				else {
					score1 += arr.get(i)*((Math.min(map.get(arr.get(i)),total_moves)/2));
					score2 += arr.get(i)*((Math.min(map.get(arr.get(i)),total_moves)+1)/2);
				}
				total_moves-=Math.min(map.get(arr.get(i)),total_moves);
				flag=!flag;
			}
			score1 = Math.max(score1,score2);
			System.out.println(score1);
		}

	}

}


import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

public class SubstringRemovalGame {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int tests = sc.nextInt();
		for(int t=0; t<tests; t++) {

			String str = sc.next();
			HashMap<Integer,Integer> map = new HashMap<>();
			ArrayList<Integer> arr = new ArrayList<>();
			int count = 0;
			int total_moves = 0;
			for(int i=0; i<str.length(); i++) {
				if(str.charAt(i)=='0' && count>0) {
					//System.out.print(count+" ");
					if(map.containsKey(count)) {
						map.put(count,map.get(count)+1);
					}
					else {
						map.put(count,1);
						arr.add(count);
					}
					total_moves++;
					count=0;
				}
				else if(str.charAt(i)=='1'){
					count++;
				}
			}
			if(count>0) {
				//System.out.print(count+" ");
				if(map.containsKey(count)) {
					map.put(count,map.get(count)+1);
				}
				else {
					map.put(count,1);
					arr.add(count);
				}
				total_moves++;
			}

			int score = 0;
			boolean flag = true;
			Collections.sort(arr);

			for(int i=arr.size()-1; i>=0 && total_moves>0; i--) {
				if(flag) {
					score += arr.get(i)*((Math.min(map.get(arr.get(i)),total_moves)+1)/2);
				}
				else {
					score += arr.get(i)*((Math.min(map.get(arr.get(i)),total_moves)/2));
				}
				total_moves-=Math.min(map.get(arr.get(i)),total_moves);
				flag=!flag;
			}
			System.out.println(score);
		}

	}

}


import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

public class SubstringRemovalGame {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int tests = sc.nextInt();
		for(int t=0; t<tests; t++) {

			String str = sc.next();
			HashMap<Integer,Integer> map = new HashMap<>();
			ArrayList<Integer> arr = new ArrayList<>();
			int count = 0;
			int total_moves = 0;
			for(int i=0; i<str.length(); i++) {
				if(str.charAt(i)=='0' && count>0) {
					//System.out.print(count+" ");
					if(map.containsKey(count)) {
						map.put(count,map.get(count)+1);
					}
					else {
						map.put(count,1);
						arr.add(count);
					}
					total_moves++;
					count=0;
				}
				else if(str.charAt(i)=='1'){
					count++;
				}
			}
			if(count>0) {
				//System.out.print(count+" ");
				if(map.containsKey(count)) {
					map.put(count,map.get(count)+1);
				}
				else {
					map.put(count,1);
					arr.add(count);
				}
				total_moves++;
			}

			int score = 0;
			boolean flag = true;
			Collections.sort(arr);
			for(int i=arr.size()-1; i>=0 && total_moves>0; i--) {
				/*if(arr.get(i)==1) {
					break;
				}*/
				if(flag) {
					score += arr.get(i)*((Math.min(map.get(arr.get(i)),total_moves)+1)/2);
				}
				else {
					score += arr.get(i)*(Math.min(map.get(arr.get(i)),total_moves)/2);
				}
				total_moves-=Math.min(map.get(arr.get(i)),total_moves);
				flag=!flag;
			}
			/*if(flag) {
				score+=(total_moves+1)/2;
			}
			else {
				score+=(total_moves)/2;
			}*/
			System.out.println(score);
		}

	}

}


import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

public class SubstringRemovalGame {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int tests = sc.nextInt();
		for(int t=0; t<tests; t++) {

			String str = sc.next();
			HashMap<Integer,Integer> map = new HashMap<>();
			ArrayList<Integer> arr = new ArrayList<>();
			int count = 0;
			int total_moves = 0;
			for(int i=0; i<str.length(); i++) {
				if(str.charAt(i)=='0' && count>0) {
					//System.out.print(count+" ");
					if(map.containsKey(count)) {
						map.put(count,map.get(count)+1);
					}
					else {
						map.put(count,1);
						arr.add(count);
					}
					total_moves++;
					count=0;
				}
				else if(str.charAt(i)=='1'){
					count++;
				}
			}
			if(count>0) {
				//System.out.print(count+" ");
				if(map.containsKey(count)) {
					map.put(count,map.get(count)+1);
				}
				else {
					map.put(count,1);
					arr.add(count);
				}
				total_moves++;
			}

			int score = 0;
			boolean flag = true;
			Collections.sort(arr);
			for(int i=arr.size()-1; i>=0 && total_moves>0; i--) {
				if(arr.get(i)==1) {
					break;
				}
				if(flag) {
					score += arr.get(i)*Math.min(map.get(arr.get(i)),total_moves);
				}
				total_moves-=Math.min(map.get(arr.get(i)),total_moves);
				flag=!flag;
			}
			if(flag) {
				score+=(total_moves+1)/2;
			}
			else {
				score+=(total_moves)/2;
			}
			System.out.println(score);
		}

	}

}


import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class SubstringRemovalGame {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int tests = sc.nextInt();
		for(int t=0; t<tests; t++) {

			String str = sc.next();

			ArrayList<Integer> arr = new ArrayList<>();
			int count = 0;
			for(int i=0; i<str.length(); i++) {
				if(str.charAt(i)=='0' && count>0) {
						arr.add(count);
						count=0;
				}
				else if(str.charAt(i)=='1'){
					count++;
				}
			}
			if(count>0) {
				arr.add(count);
			}

			int score = 0;

			Collections.sort(arr);

			for(int i=arr.size()-1; i>=0; i-=2) {
				score+=arr.get(i);
			}
			System.out.println(score);
		}

	}

}


import java.util.*;

public class SubstringRemovalGame {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int t = s.nextInt();
    while (t-- > 0) {
      boolean aliceTurn = true;
      int aliceScore = 0;
      String bits = s.next();
      while (bits.length() > 0) {
        int maxIndex = 0;
        int maxLength = 0;
        for (int i = 0; i < bits.length(); ++i) {
          char c = bits.charAt(i);
          if (c == '1') {
            int length = 1;
            for (int j = i + 1; j < bits.length() && bits.charAt(j) == c; ++j) {
              ++length;
            }
            if (length > maxLength) {
              maxLength = length;
              maxIndex = i;
            }
          }
        }
        if (maxLength == 0) {
          bits = bits.substring(1);
        } else {
          if (aliceTurn) {
            aliceScore += maxLength;
          }
          bits = bits.substring(0, maxIndex) + bits.substring(maxIndex + maxLength);
        }
        aliceTurn = !aliceTurn;
      }
      System.out.println(aliceScore);
    }
  }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.StringTokenizer;

public class B {

	public static void main(String[]args) {
		FastReader fs=new FastReader();
		int t=fs.nextInt();
		for(int tt=0;tt<t;tt++) {
			String s=fs.nextLine();
		//	System.out.println(solve(s));
			solve(s);

		}
	}
	public static void solve(String s) {
		String []ss=s.split("0");
		List<String>l=new ArrayList<>();
		for(String st:ss) {
			if(st!=null||st.length()!=0)
				l.add(st);
		}
		int arr[]=new int[l.size()];

		for(int i=0;i<l.size();i++)
			arr[i]=l.get(i).length();

		Arrays.sort(arr);

		int count=0;
		for(int i=arr.length-1;i>=0;i-=2)
			count+=arr[i];

			System.out.println(count);

	}

	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(new
					InputStreamReader(System.in));
		}

		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt()
		{
			return Integer.parseInt(next());
		}

		long nextLong()
		{
			return Long.parseLong(next());
		}

		double nextDouble()
		{
			return Double.parseDouble(next());
		}

		String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}

}


/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in = new Scanner(System.in);
		int t=in.nextInt() ;
		while(t-->0)
		{
			String s =in.next() ;String[] str=s.split("0") ;
			Arrays.sort(str) ;int c=0 ;
			for(int i=str.length-1;i>=0;i=i-2)
			{
				if(str[i].length()>0)
				{
					c+=str[i].length() ;
				}
			}
			System.out.println(c) ;
		}
	}
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class _0122SubstirngRemovalGame {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int cases = sc.nextInt();
		sc.nextLine();
		while(cases>0) {
		String patt = sc.nextLine()+"0";
		int curr=0;
		List<Integer> store = new ArrayList<>();
		for(int i=0;i<patt.length();i++) {
			if(patt.charAt(i)=='1') {
				curr++;
			}
			else {
				store.add(curr);
				curr=0;
			}
		}
		Collections.sort(store,Collections.reverseOrder());

	//	System.out.println(store);
		int Alice=0;
		for(int i=0;i<store.size();i+=2) {
			Alice+=store.get(i);
		}
		System.out.println(Alice);
			cases--;
		}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
public class SubstringRemovalGame {
    public static void main(String[] args) throws IOException{
        BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
        int t=Integer.parseInt(r.readLine());
        while(t-->0){
            String s=r.readLine();
            int n=s.length();
            ArrayList<Integer>list=new ArrayList<>();
            int count=0;
            for(int i=0;i<n;i++){
                char c=s.charAt(i);
                if(c=='0'&&count!=0){
                    list.add(count);
                    count=0;
                }
                if(c=='1')
                    count++;
            }
            if(count!=0)
                list.add(count);
            Collections.sort(list,Collections.reverseOrder());
            int size=list.size();
            int sum=0;
            for(int i=0;i<size;i+=2)
                sum+=list.get(i);
            System.out.println(sum);
        }
    }
}


//package Practice_L1000;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class P_1398B {
    static final FS sc = new FS();
    static final PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) {
        int t = sc.nextInt();
        while(t-->0){
            String s = sc.next();
            char[] c = s.toCharArray();
            int n = c.length;
            ArrayList<Integer> ind = new ArrayList<>();
            int count = 0;
            for(int i=0; i<n; i++){
                if(c[i]=='1'){
                    count++;
                }
                else{
                    ind.add(count);
                    count = 0;
                }
            }
            if(count!=0){
                ind.add(count);
            }
            Collections.sort(ind, Collections.reverseOrder());
            int sum = 0;
            for(int i=0; i<ind.size(); i+=2){
                sum += ind.get(i);
            }
            System.out.println(sum);
        }
    }

    static class FS {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception ignored) {
                }
            }
            return st.nextToken();
        }

        int[] nextArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextLong();
            }
            return a;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int t = fs.nextInt();
		for (int k = 1; k <= t; k++) {
			//int n=fs.nextInt();
			String s[]=fs.next().split("");
			int n=s.length;
			int arr[]=new int[n];

			int sum=0;
			int index=0;
			for(int i=0;i<n;i++){
				if(s[i].equals("0")){

				    if(i>0){
				        arr[index++]=sum;
				    }
				    sum=0;
					continue;
				}
				else{
				    sum+=Integer.parseInt(s[i]);
				}

			}
			arr[index]=sum;
			Arrays.sort(arr);
			/*for(int i:arr){
			    out.print(i+" ");
			}
			out.println();*/
			int max=0;
			int odd=0;
			int even=0;
			boolean flag=true;
			for(int i=0;i<n;i++){
				if(arr[i]==0){
					continue;
				}
				if(flag){
					odd+=arr[i];
					flag=false;
				}
				else{
					even+=arr[i];
					flag=true;
				}
			}
			max=Math.max(odd,even);
			out.println(max);

		}

		out.close();
	}

    /*	public static int solver(int arr[], int n) {

		/*
		 * Stack<Long> stack=new Stack<>(); stack.push(arr[0]); Long operations=0L;
		 * boolean dec=false; for(int i=1;i<=n;i++){
		 * if(!stack.isEmpty()&&i<n&&arr[i]<stack.peek()){ dec=true; } Long
		 * h=(i==n)?Long.MAX_VALUE:arr[i]; while(stack.size()>1&&dec&&stack.peek()<h){
		 * operations++; Long element=stack.pop(); element++;
		 * if(element!=stack.peek()&&element!=h){ stack.push(element); } }
		 * if(stack.peek()>h){ stack.push(h); } else
		 * if(stack.peek()<h&&h!=Long.MAX_VALUE){ stack.pop(); stack.push(h); } }
		 */

	public static int gcd(int a, int b) {
		if (a == 0)
			return b;

		return gcd(b % a, a);
	}

	static int gcdCoeff(int a, int b, int arr[])// euclidean gcd + extended euclidean
	{
		if (b == 0)
			return a;
		int tmp[] = { 1, 1 };// must be 1,1, because at base step b=0, a=anything, 1.0+ 1.a=a
		int result = gcdCoeff(b, a % b, tmp);
		arr[0] = tmp[1];// x=y1
		arr[1] = (tmp[0] - (a / b) * tmp[1]);// y=(x1-(a/b)*y1)
		return result;
	}

	static class PairIndex {
		long val;
		long index;

		public PairIndex(long val, long index) {
			this.val = val;
			this.index = index;
		}

	}

	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			while (!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] readIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		Long[] readLongArray(int n) {
			Long[] a = new Long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}
}


import java.io.*;
import java.util.*;

public class solution {
    static class sort implements Comparator<ArrayList<Integer>> {

        @Override
        public int compare(ArrayList<Integer> o1, ArrayList<Integer> o2) {
            int c = o2.get(1).compareTo(o1.get(1));
            if (c == 0) {

                c = o2.get(0).compareTo(o1.get(0));
            }
            return c;
        }
    }

    public static void merge(long arr[], int l, int m, int r) {
        int n1 = m - l + 1;
        int n2 = r - m;
        long L[] = new long[n1];
        long R[] = new long[n2];
        for (int i = 0; i < n1; ++i)
            L[i] = arr[l + i];
        for (int j = 0; j < n2; ++j)
            R[j] = arr[m + 1 + j];
        int i = 0, j = 0;
        int k = l;
        while (i < n1 && j < n2) {
            if (L[i] <= R[j]) {
                arr[k] = L[i];
                i++;
            } else {
                arr[k] = R[j];
                j++;
            }
            k++;
        }
        while (i < n1) {
            arr[k] = L[i];
            i++;
            k++;
        }
        while (j < n2) {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    public static void sort(long arr[], int l, int r) {
        if (l < r) {
            int m = (l + r) / 2;
            sort(arr, l, m);
            sort(arr, m + 1, r);
            merge(arr, l, m, r);
        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        } else return gcd(b, a % b);
    }

    public static long lcm(long a, long b) {
        long gcd = gcd(a, b);
        long pord = a * b;
        return pord / gcd;
    }

    static class graphs {
        private int V;
        private ArrayList<Integer> adj[];

        graphs(int v) {
            V = v;
            adj = new ArrayList[v];
            for (int i = 0; i < v; i++) {
                adj[i] = new ArrayList<>();
            }
        }

        void addedge(int u, int v) {
            adj[u].add(v);
        }

        void BFS(int v) {
            boolean visited[] = new boolean[V];
            Queue<Integer> Q = new LinkedList<>();
            visited[v] = true;
            Q.add(v);
            while (!Q.isEmpty()) {
                int temp = Q.peek();
                System.out.print(temp + " ");
                Q.remove();
                Iterator<Integer> it = adj[temp].listIterator();
                while (it.hasNext()) {
                    int n = it.next();
                    if (!visited[n]) {
                        visited[n] = true;
                        Q.add(n);
                    }
                }
            }
        }

        void DFSUtil(int v, boolean visited[]) {
            visited[v] = true;
            System.out.print(v + " ");
            Iterator<Integer> it = adj[v].listIterator();
            while (it.hasNext()) {
                int n = it.next();
                if (!visited[n]) {
                    DFSUtil(n, visited);
                }
            }
        }

        void DFS(int v) {
            boolean visited[] = new boolean[V];
            DFSUtil(v, visited);
        }
    }

    public static int Binaraysearch(long a[], int low, int high, long key) {
        while (low <= high) {
            int mid = low + (high - low) / 2;
            if (a[mid] == key) {
                return mid;
            } else if (a[mid] < key) {
                low = mid;
            } else {
                high = mid;
            }
        }
        return -1;
    }

    public static void seive(boolean prime[]) {
        Arrays.fill(prime, true);
        int n = prime.length - 1;
        for (int p = 2; p * p <= n; p++) {
            if (prime[p] == true) {
                for (int i = p * p; i <= n; i += p)
                    prime[i] = false;
            }
        }
    }

    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        for(int ii=0;ii<t;ii++){
            String s = br.readLine();
            ArrayList<Integer>A = new ArrayList<>();
            int count = 0;
            for(int i=0;i<s.length();i++){
                if(s.charAt(i) == '1'){
                    count++;
                }
                else{
                    A.add(count);
                    count = 0;
                }
            }
            A.add(count);
            Collections.sort(A);
            int ans = 0;
            for(int i=A.size()-1;i>=0;i-=2){
                ans+=A.get(i);
            }
            System.out.println(ans);
        }
    }
}


import java.util.*;
public class Main
{

	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();

		while(t-->0)
		{
		int c = 0,j=0;
		String s = sc.next();
	        int a[] = new int[100];
	        for(int i = 0; i<s.length(); i++)
	        {
	            if(s.charAt(i  ) == '1' )
	                a[j]++;

	            if(s.charAt(i  ) == '0' )
	                j++;
	        }

	         sort(a);
            // int c = 0;
	        for(int i = 0; i<100; i+=2)
	        {
	            if(a[i] == 0)
	                break;
	           c+=a[i];
	           //System.out.println(a[i]);
	        }

	        System.out.println(c);
		}
	}
	public static void sort(int array[])
	{
	    int num = array.length,i,j,temp;
	    for (i = 0; i < ( num - 1 ); i++) {
      for (j = 0; j < num - i - 1; j++) {
        if (array[j] < array[j+1])
        {
          temp = array[j];
          array[j] = array[j+1];
          array[j+1] = temp;
        }
      }

	}}

}


import java.util.*;
import java.io.*;

public final class GFG {
	public static void main (String[] args)throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	int t = Integer.parseInt(br.readLine());
	while(t-->0)
	{
	    int c = 0;
	    String s = br.readLine();
	    int turn = 1;
	  while(s.contains("1"))
	 {
	     int x=0;

	    for(int i = 0; i<s.length(); i++)
	        if(s.charAt(s.length()-i-1) =='1')
	        x+=Math.pow(2,i);
	   int count = 0;
	   String r = "";
	    while(x!=0)
	    {
	          x = (x & (x << 1));
            r+="1";
            count++;
	    }

	    if(turn == 1)
	    {
	     turn = 2;
	     c+=count;
	    }
	    else
	        turn = 1;

	  s = s.replaceFirst(r,"");
	  System.out.println(s);
	 }

	 System.out.println(c);

	}

	}
}


import java.util.*;
import java.io.*;

public class GFG {
	public static void main (String[] args)throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	int t = Integer.parseInt(br.readLine());
	while(t-->0)
	{
	    int c = 0;
	    String s = br.readLine();
	    int turn = 1;
	  while(s.contains("1"))
	 {
	     int x=0;

	    for(int i = 0; i<s.length(); i++)
	        if(s.charAt(s.length()-i-1) =='1')
	        x+=Math.pow(2,i);
	   int count = 0;
	   String r = "";
	    while(x!=0)
	    {
	          x = (x & (x << 1));
            r+="1";
            count++;
	    }

	    if(turn == 1)
	    {
	     turn = 2;
	     c+=count;
	    }
	    else
	        turn = 1;

	  s = s.replaceFirst(r,"");

	 }

	 System.out.println(c);

	}

	}
}


import java.util.*;
import java.lang.*;
import java.io.*;

public class MoreCase {
	static PrintWriter out = new PrintWriter(System.out);
	static FastScanner fs = new FastScanner();
	public static void main(String[] args) {
		int t = fs.nextInt();
		while(t!=0)
		{
			Solve();
			t-=1;
		}
		out.flush();
	}
	static void Solve()
	{
		String s = fs.next();
		ArrayList<Integer> AL = new ArrayList<>();
		int t=0;
		for(int i=0;i<s.length();i++)
		{
			if(s.charAt(i)=='1') t+=1;
			else {
				if(t!=0)
				{
					AL.add(t);
				}
				t=0;
			}
		}
		if(t!=0) AL.add(t);
		Collections.sort(AL,Collections.reverseOrder());
		int res=0;
		for(int i=0;i<AL.size();i+=2)
		{
			res+=AL.get(i);
		}
		out.println(res);
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.lang.*;

public class MoreCase {
	static Scanner sc = new Scanner(System.in);
	static void Solve()
	{
		String s = sc.next();
		ArrayList<Integer> AL = new ArrayList<>();
		int t=0;
		for(int i=0;i<s.length();i++)
		{
			if(s.charAt(i)=='1') t+=1;
			else {
				if(t!=0)
				{
					AL.add(t);
				}
				t=0;
			}
		}
		if(t!=0) AL.add(t);
		Collections.sort(AL,Collections.reverseOrder());
		int res=0;
		for(int i=0;i<AL.size();i+=2)
		{
			res+=AL.get(i);
		}
		System.out.println(res);
	}
	public static void main(String[] args) {
		int t = sc.nextInt();
		while(t!=0)
		{
			Solve();
			t-=1;
		}
	}
}


/*
 ******************************************************************************
 * MIT License                                                                *
 * Copyright (c) 2020 - Present Viral Lalakia                                 *
 ******************************************************************************
 */

// package com.virallalakia.codeforces;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * This is a solution for Substring Removal Game problem of Codeforces.
 * This is verified on https://codeforces.com. Package definition needs to be removed before submission.
 *
 * @author Viral Lalakia
 */
public class SubstringRemovalGame {

  private static final Scanner SYS_IN =
      new Scanner(new BufferedReader(new InputStreamReader(System.in)));

  /**
   * Main method for solution. Calls to evaluate one or more test cases.
   */
  public static void main(String[] args) {
    final int t = SYS_IN.nextInt(); // total test cases
    for (int ti = 0; ti < t; ti++) {
      evaluateCase();
    }
    SYS_IN.close();
  }

  /**
   * Evaluate a test case. Handles I/O.
   */
  private static void evaluateCase() {
    try {
      final char[] ip = (SYS_IN.nextLine() + "0").toCharArray();
      List<Integer> nums = new ArrayList();
      int lastZero = -1;
      for (int i = 0; i < ip.length; i++) {
        if (ip[i] == '0') {
          if (lastZero + 1 < i) {
            nums.add(i - lastZero - 1);
          }
          lastZero = i;
        }
      }
      Collections.sort(nums);

      int ans = 0;
      for (int ni = nums.size() - 1; ni >= 0; ni -= 2) {
        ans += nums.get(ni);
      }
      System.out.println(ans);
    } catch (Exception e) {}
  }
}


/*
 ******************************************************************************
 * MIT License                                                                *
 * Copyright (c) 2020 - Present Viral Lalakia                                 *
 ******************************************************************************
 */

// package com.virallalakia.codeforces;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * This is a solution for Substring Removal Game problem of Codeforces.
 * This is verified on https://codeforces.com. Package definition needs to be removed before submission.
 *
 * @author Viral Lalakia
 */
public class SubstringRemovalGame {

  private static final Scanner SYS_IN =
      new Scanner(new BufferedReader(new InputStreamReader(System.in)));

  /**
   * Main method for solution. Calls to evaluate one or more test cases.
   */
  public static void main(String[] args) {
    final int t = SYS_IN.nextInt(); // total test cases
    SYS_IN.nextLine();
    for (int ti = 0; ti < t; ti++) {
      evaluateCase();
    }
    SYS_IN.close();
  }

  /**
   * Evaluate a test case. Handles I/O.
   */
  private static void evaluateCase() {
    try {
      final char[] ip = (SYS_IN.nextLine() + "0").toCharArray();
      List<Integer> nums = new ArrayList();
      int lastZero = -1;
      for (int i = 0; i < ip.length; i++) {
        if (ip[i] == '0') {
          if (lastZero + 1 < i) {
            nums.add(i - lastZero - 1);
          }
          lastZero = i;
        }
      }
      Collections.sort(nums);

      int ans = 0;
      for (int ni = nums.size() - 1; ni >= 0; ni -= 2) {
        ans += nums.get(ni);
      }
      System.out.println(ans);
    } catch (Exception e) {}
  }
}


// Dummy text
import java.io.*;
import java.util.*;
  public class Deletion
  {
    public static void main(String[] args) throws IOException
    {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      int t = Integer.parseInt(br.readLine());
       while (t-- > 0)
       {
           String line = br.readLine();
           int arr[]=new int[line.length()];
           for(int y=0;y<line.length();y++ )
           arr[y]=0;
           int k=0;
           int z=0;
           for(int i=0;i<line.length();i++)
           {
               if((int)line.charAt(i)==49)
               z++;
               else
               {
                   arr[k]=z;
                   k++;
                   z=0;
                }
            }
            arr[k]=z;
            k++;
            z=0;
            Arrays.sort(arr);
            int sum=0;

            for(int y=line.length()-1;y>=0;y-=2 )
            sum+=arr[y];
            System.out.println(sum);
        }
        }
    }


// Dummy text
import java.io.*;
import java.util.*;
  public class Deletion
  {
    public static void main(String[] args) throws IOException
    {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      int t = Integer.parseInt(br.readLine());
       while (t-- > 0)
       {
           String line = br.readLine();
           int arr[]=new int[line.length()];
           for(int y=0;y<line.length();y++ )
           arr[y]=0;
           int k=0;
           int z=0;
           for(int i=0;i<line.length();i++)
           {
               if((int)line.charAt(i)==49)
               z++;
               else
               {
                   arr[k]=z;
                   k++;
                   z=0;
                }
            }
            if(z!=0)
            {
            arr[k]=z;
            k++;
            z=0;
        }
            Arrays.sort(arr);
            int sum=0;

            for(int y=line.length()-1;y>=0;y-=2 )
            sum+=arr[y];
            System.out.println(sum);
        }
        }
    }