import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class B {
	static InputReader scn = new InputReader(System.in);
	static OutputWriter out = new OutputWriter(System.out);

	public static void main(String[] args) {
		int t = scn.nextInt();
		while (t-- > 0) {
			solve();
		}
		out.close();
	}

	public static void solve() {
		String s = scn.next();
		ArrayList<Integer> list = new ArrayList<Integer>();
		int n = s.length();
		int counter = 0;
		for (int i = 0; i < n; i++) {
			char ch = s.charAt(i);
			if (ch == '1') {
				counter++;
				if (i == n - 1)
					list.add(counter);
			} else {
				list.add(counter);
				counter = 0;
			}
		}
		Collections.sort(list);
		int len = list.size();
		int ans = 0;
		for (int i = len - 1; i >= 0; i--) {
			ans += list.get(i);
			i--;
		}
		out.println(ans);
	}

	public static ArrayList<Integer> Divisor(int a) {
		ArrayList<Integer> list = new ArrayList<>();
		for (int i = 2; i <= Math.sqrt(a); i++) {
			if (a % i == 0) {
				list.add(i);
				int x = a / i;
				if (a % x == 0) {
					list.add(x);
				}
			}
		}
		return list;
	}

	public static HashMap<Integer, Integer> CountFrequencies(int[] arr) {
		HashMap<Integer, Integer> map = new HashMap<>();
		for (int i = 0; i < arr.length; i++) {
			int a = arr[i];
			if (map.containsKey(a)) {
				map.put(a, map.get(a) + 1);
			} else {
				map.put(a, 1);
			}
		}
		return map;
	}

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

	public static int lcm(int a, int b) {
		return (a * b) / gcd(a, b);
	}

	public static ArrayList<String> GetSubSequences(String s) {
		if (s.length() == 0) {
			ArrayList<String> br = new ArrayList<>();
			br.add("");
			return br;
		}
		char ch = s.charAt(0);
		String ms = s.substring(1);

		ArrayList<String> rr = GetSubSequences(ms);

		ArrayList<String> mr = new ArrayList<>();

		int t = rr.size();
		for (int i = 0; i < t; i++) {
			mr.add(rr.get(i));
			mr.add(ch + rr.get(i));

		}

		return mr;

	}

	public static void printSubsequences(String[] str, int n) {
		/* Number of subsequences is (2**n -1) */
		int opsize = (int) Math.pow(2, n);
		for (int counter = 1; counter < opsize; counter++) {
			for (int j = 0; j < n; j++) {
				/*
				 * Check if jth bit in the counter is set If set then print jth element from
				 * arr[]
				 */

				if (BigInteger.valueOf(counter).testBit(j))
					System.out.print(str[j] + " ");
			}
			System.out.println();
		}
	}

	public static int[] readArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = scn.nextInt();
		}
		return a;
	}

	static void sort(int[] a) {
		ArrayList<Integer> l = new ArrayList<>();
		for (int i : a) {
			l.add(i);
		}
		Collections.sort(l);
		for (int i = 0; i < a.length; i++) {
			a[i] = l.get(i);
		}
	}

	public static int binarySearch(int arr[], int l, int r, int x) {
		if (r >= l) {
			int mid = l + (r - l) / 2;
			if (arr[mid] == x)
				return mid;
			if (arr[mid] > x)
				return binarySearch(arr, l, mid - 1, x);
			return binarySearch(arr, mid + 1, r, x);
		}
		return -1;
	}

	public static int firstOccurence(int array1[], int low, int high, int x, int n) {
		if (low <= high) {
			int mid = low + (high - low) / 2;
			if ((mid == 0 || x > array1[mid - 1]) && array1[mid] == x)
				return mid;
			else if (x > array1[mid])
				return firstOccurence(array1, (mid + 1), high, x, n);
			else
				return firstOccurence(array1, low, (mid - 1), x, n);
		}
		return -1;
	}

	public static int lastOccurence(int array2[], int low, int high, int x, int n) {
		if (low <= high) {
			int mid = low + (high - low) / 2;
			if ((mid == n - 1 || x < array2[mid + 1]) && array2[mid] == x)
				return mid;
			else if (x < array2[mid])
				return lastOccurence(array2, low, (mid - 1), x, n);
			else
				return lastOccurence(array2, (mid + 1), high, x, n);
		}
		return -1;
	}

	public static boolean isPrime(long n) {
		if (n < 2)
			return false;
		if (n == 2 || n == 3)
			return true;
		if (n % 2 == 0 || n % 3 == 0)
			return false;
		long sqrtN = (int) Math.sqrt(n) + 1;
		for (long i = 6L; i <= sqrtN; i += 6) {
			if (n % (i - 1) == 0 || n % (i + 1) == 0)
				return false;
		}
		return true;
	}

	public static void quickSort(int[] arr, int lo, int hi) {
		if (lo >= hi) {
			return;
		}
		int mid = (lo + hi) / 2;
		int pivot = arr[mid];
		int left = lo;
		int right = hi;
		while (left <= right) {
			while (arr[left] < pivot) {
				left++;
			}
			while (arr[right] > pivot) {
				right--;
			}
			if (left <= right) {
				int temp = arr[left];
				arr[left] = arr[right];
				arr[right] = temp;
				left++;
				right--;
			}
		}
		quickSort(arr, lo, right);
		quickSort(arr, left, hi);
	}

	static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String next() {
			return nextLine();
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}

	static class OutputWriter {
		private final PrintWriter writer;

		public OutputWriter(OutputStream outputStream) {
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
		}

		public OutputWriter(Writer writer) {
			this.writer = new PrintWriter(writer);
		}

		public void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0) {
					writer.print(' ');
//                    writer.print(1);
				}
				writer.print(objects[i]);
			}
		}

		public void println(Object... objects) {
			print(objects);
			writer.println();
		}

		public void close() {
			writer.close();
		}
	}

}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class B {

    static Scanner scn = new Scanner(System.in);

	public static void main(String[] args) {
		int t = scn.nextInt();
		while (t-- > 0) {
			solve();
		}
	}

	public static void solve() {

		String s = scn.next();
		ArrayList<Integer> list = new ArrayList<Integer>();
		int n = s.length();
		int counter = 0;
		for (int i = 0; i < n; i++) {
			char ch = s.charAt(i);
			if (ch == '1') {
				counter++;
				if (i == n - 1)
					list.add(counter);
			} else {
				list.add(counter);
				counter = 0;
			}
		}
		Collections.sort(list);
		int len = list.size();
		int ans = 0;
		for (int i = len - 1; i >= 0; i--) {
			ans += list.get(i);
			i--;
		}
		System.out.println(ans);
	}
}


//import java.util.*;
//
//public class A {
//    static Scanner s = new Scanner(System.in);
//    public static void main(String[] args){
//
//    }
//}
import java.util.*;

public class B {
    static Scanner s = new Scanner(System.in);

    public static void main(String[] args){
        int t = s.nextInt();
        for(int i = 0; i < t; i++){
            String str = s.next();
            solve(str);
        }
    }

    public static void solve(String str){
        PriorityQueue<Integer> ones = new PriorityQueue<>(Comparator.reverseOrder());
        int onesRemoved = 0;
        String[] strings = str.split("0+");
        for(String s : strings) ones.offer(s.length());

        int i = 0;
        while(!ones.isEmpty()){
            if(i % 2 == 0)
                onesRemoved += ones.poll();
            else
                ones.poll();
            i++;
        }

        System.out.println(onesRemoved);
    }
}


import java.util.*;
public class solution {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0)
		{
			int n=sc.nextInt();
			int arr[]=new int[n];
			for(int i=0;i<n;i++)
				arr[i]=sc.nextInt();
			if(n==1)
				System.out.println(arr[0]);
			else
			{int index=0;
			PriorityQueue<Integer> queue=new PriorityQueue<>();
			while(index<n)
			{
			   int count=0;
			   while(index<n && arr[index]==1)
			   {   count++;
			       index++;
			   }
			   if(count>0)
				   queue.add(-count);
			   index++;
			}
			int sum=0;
			int check=0;
			while(queue.size()>=1)
			{
			 if(check%2==0)
		     	 {
				 sum+=-queue.remove();
				 check++;
			    }

			}
			System.out.println(sum);

			}

			}
		}

	}


import java.util.*;
public class solution {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0)
		{
			int n=sc.nextInt();
			int arr[]=new int[n];
			for(int i=0;i<n;i++)
				arr[i]=sc.nextInt();
			if(n==1)
				System.out.println(arr[0]);
			else
			{   int index=0;
			    PriorityQueue<Integer> queue=new PriorityQueue<>();
			   while(index<n)
			 {
			     int count=0;
			    while(index<n && arr[index]==1)
			    {   count++;
			        index++;
			    }
			   if(count>0)
				   queue.add(-count);
			   index++;
			}
			 int sum=0;
			 int check=0;
			 int temp;
			 while(queue.size()>=1)
			{
			   if(check%2==0)
		     sum+=-queue.remove();
			   else
			   temp=queue.remove();

			   check++;
			}
			 System.out.println(sum);
			}

			}

			}
		}

	}


import java.util.*;
public class solution {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0)
		{
			String arr=sc.next();
			int n=arr.length();
			if(n==1)
				System.out.println(arr.charAt(0));
			else
			{   int index=0;
			    PriorityQueue<Integer> queue=new PriorityQueue<>();
			   while(index<n)
			 {
			     int count=0;
			    while(index<n && arr.charAt(index)=='1')
			    {   count++;
			        index++;
			    }
			   if(count>0)
				   queue.add(-count);
			   index++;
			}
			 int sum=0;
			 int check=0;
			 int temp;
			 while(queue.size()>=1)
			{
			   if(check%2==0)
		       sum+=-queue.remove();
			   else
			   temp=queue.remove();

			   check++;
			}
			 System.out.println(sum);
			}

			}

			}
		}


import java.util.*;
public class solution {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0)
		{
			int n=sc.nextInt();
			int arr[]=new int[n];
			for(int i=0;i<n;i++)
				arr[i]=sc.nextInt();
			if(n==1)
				System.out.println(arr[0]);
			else
			{   int index=0;
			    PriorityQueue<Integer> queue=new PriorityQueue<>();
			   while(index<n)
			 {
			     int count=0;
			    while(index<n && arr[index]==1)
			    {   count++;
			        index++;
			    }
			   if(count>0)
				   queue.add(-count);
			   index++;
			}
			 int sum=0;
			 int check=0;
			 int temp;
			 while(queue.size()>=1)
			{
			   if(check%2==0)
		     sum+=-queue.remove();
			   else
			   temp=queue.remove();

			   check++;
			}
			 System.out.println(sum);
			}

			}

			}
		}


import java.util.*;

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

        while (tt-- > 0) {
            String s = scan.next();
            s = s + "0";
            int count = 0;

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

            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == '1') {
                    count++;
                    continue;
                }
                if (count != 0)
                    list.add(count);
                count = 0;
            }

            // System.out.println(list);

            Collections.sort(list, Collections.reverseOrder());

            int score = 0;
            for (int i = 0; i < list.size(); i++) {
                score += (i % 2 == 0) ? list.get(i) : 0;
            }

            System.out.println(score);

        }

        scan.close();
    }
}


import java.util.*;

public class SubstringRemoval
{
    public static void main (String [] args)
    {
        Scanner sc = new Scanner (System.in);
        int t = sc.nextInt();
        while(t-->0)
        {
            String s = sc.next();
            ArrayList<Integer> a = new ArrayList<Integer>();
            int index = 0;
            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);
//            Comparator <Integer> com = new comimpl();
            Collections.sort(a, new Comparator<Integer>() {
                @Override
                public int compare(Integer t1, Integer t2) {
                    if(t1>t2)
                        return -1;
                    return 1;
                }
            });

            int ans = 0;
            boolean b =true;
            for(int i =0;i<a.size();i++)
            {
                if(a.get(i)==0)
                    break;
                if(b)
                {
                    ans+=a.get(i);
                    b=false;
                }
                else
                {
                    b=true;
                }
            }
             System.out.println(ans);
        }

    }
}


import java.util.*;

public class SubstringRemoval
{
    public static void main (String [] args)
    {
        Scanner sc = new Scanner (System.in);
        int t = sc.nextInt();
        while(t-->0)
        {
            String s = sc.next();
//            ArrayList<Integer> a = new ArrayList<Integer>();
            int a[] = new int [ s.length()+50];
            int index = 0;
            int count = 0;
            for(int i = 0 ;i<s.length();i++)
            {
                if(s.charAt(i)=='1')
                    count++;
                else
                {
                    a[index]= count;
                    index++;
                    count = 0;
                }
            }
            a[index]=count;
//            Comparator <Integer> com = new comimpl();
//            Collections.sort(a, new Comparator<Integer>() {
//                @Override
//                public int compare(Integer t1, Integer t2) {
//                    if(t1>t2)
//                        return -1;
//                    return 1;
//                }
//            });
            Arrays.sort(a);
            int ans = 0;
            boolean b =true;
            for(int i =a.length-1;i>=0;i--)
            {
                if(a[i]==0)
                    break;
                if(b)
                {
                    ans+=a[i];
                    b=false;
                }
                else
                {
                    b=true;
                }
            }
             System.out.println(ans);
        }

    }
}


import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }
    static class Solver {
        public void solve(InputReader in, PrintWriter out) {
            int t = in.nextInt();
            while (t-- > 0) {
                String s = in.next();
                StringTokenizer tok = new StringTokenizer(s, "0");
                int[] ones = new int[tok.countTokens()];
                int ind = 0;
                while (tok.hasMoreTokens()) {
                    ones[ind++] = tok.nextToken().length();
                }
                Arrays.sort(ones);
                int count = 0;
                for (int i = ones.length - 1; i >= 0; i -= 2) {
                    count += ones[i];
                }
                out.println(count);
            }
        }
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreElements()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public String nextLine() {
            String s = "";
            try {
                s = reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return s;
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


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

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int t=in.nextInt();
        for(int i=0;i<t;i++)
        TaskB.solve(0,in,out);
        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}
class TaskB {
    static String s;
    public static void solve(int testNumber, Main.InputReader in, PrintWriter out) {
        s=in.next();
        int a=0;
        int i=0;
        while(s.contains("1"))
        {
            int cc=countOneMax();
            if(i%2==0)
                a+=cc;
            i++;
        }
        out.println(a);
    }
    public static int countOneMax()
    {
        int x=Integer.valueOf(s,2);
        int count=0;
        while(x!=0)
        {
            x=x&(x<<1);
            count++;
        }
        StringBuilder y= new StringBuilder();
        y.append("1".repeat(Math.max(0, count)));
        if(y.length()==1)
        {
            int index=0;
          for(int i=0;i<s.length();i++) {
              if (s.charAt(i) == '1') {
                  index = i;
                  break;
              }
          }
           s=s.substring(index+1);
        }
        else
        s=s.replace(y,"");
        return count;
    }
}


import java.io.*;
import java.util.StringTokenizer;
import java.util.ArrayList;
import java.util.Collections;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int t=in.nextInt();
        for(int i=0;i<t;i++)
        TaskB.solve(0,in,out);
        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}
class TaskB {
    static String s;
    public static void solve(int testNumber, Main.InputReader in, PrintWriter out) {
        s=in.next();
        ArrayList<Integer> oneCounter=new ArrayList<>();
        int count=0;
        for(int i=0;i<s.length();i++)
        {
            if(s.charAt(i)=='1')
                count++;
            else
            {
                if(count!=0)
                oneCounter.add(count);
                count=0;
            }
        }
        if(count!=0)
            oneCounter.add(count);
        Collections.sort(oneCounter);
        Collections.reverse(oneCounter);
        int c=0;
        int a=0;
        for(int i: oneCounter)
        {
            if(c%2==0)
                a+=i;
            c++;
        }
        out.println(a);
    }
}


import java.util.PriorityQueue;
import java.util.Scanner;

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

    int t= sc.nextInt();
    while(t-- > 0)
    {
        String s=sc.next();
        PriorityQueue<String> pq  =  new PriorityQueue<>((a,b)->b.length()-a.length());
        for(String str : s.split("0"))
        {
            pq.add(str);
        }
        int alice=0;
        while(!pq.isEmpty())
        {
            alice+=pq.poll().length();
            if(!pq.isEmpty())
                pq.poll();
        }
        System.out.println(alice);
    }
    }
}


import java.util.Scanner;
import java.util.Arrays;

public class SubstringRemoval {

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

		int t = sc.nextInt();
		int answer;
		while (t > 0) {
			String s = sc.next();
			int count = 0;
			int k = 0;
			int[] arr = new int[s.length()];
			for (int i = 0; i < s.length(); i++) {
				if (s.charAt(i) == '1') {
					count++;
					if(i==s.length()-1) {
						arr[k] = count;
					}
				} else if (s.charAt(i) == '0' ) {
					if (count != 0) {
						arr[k] = count;
						count = 0;
						k++;
					}
				}
			}
			Arrays.sort(arr);
			answer = 0;
			for (int j = arr.length-1; j >= 0; j -= 2) {
				answer += arr[j];
			}
			System.out.println(answer);
			t--;
		}
		sc.close();
	}
}


import java.util.Scanner;
import java.util.Arrays;

public class SubstringRemoval {

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

		int t = sc.nextInt();
		int answer;
		while (t > 0) {
			String s = sc.next();
			int count = 0;
			int k = 0;
			int[] arr = new int[s.length()];
			for (int i = 0; i < s.length(); i++) {
				if (s.charAt(i) == '1') {
					count++;
					if(i==s.length()-1) {
						arr[k] = count;
					}
				} else if (s.charAt(i) == '0' ) {
					if (count != 0) {
						arr[k] = count;
						count = 0;
						k++;
					}
				}
			}
			Arrays.sort(arr);
			answer = 0;
			for (int j = arr.length-1; j > 0; j -= 2) {
				answer += arr[j];
			}
			System.out.println(answer);
			t--;
		}
		sc.close();
	}
}


import java.io.*;
import java.util.*;
public class SubstringRemovalGame
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0)
        {
            String s=sc.next();
            List<Integer> list=new ArrayList();
            int i=0;
            while(i<s.length())
            {
                if(s.charAt(i)=='1' && i!=s.length()-1)
                {
                    int j=i+1,count=1;
                    while(s.charAt(j)=='1')
                    {
                        count++;
                        j++;
                        if(j>s.length()-1)
                            break;
                    }
                    list.add(count);
                    i=j;
                }
                else
                    i++;
            }
            if(s.charAt(s.length()-2)=='0' && s.charAt(s.length()-1)=='1')
                list.add(1);
            Collections.sort(list,Collections.reverseOrder());
            if(list.size()==0)
                System.out.println(0);
            else if(list.get(0)==1)
            {
                if(list.size()%2==0)
                    System.out.println((list.size()/2));
                else
                    System.out.println(((list.size()/2)+1));
            }
            else
            {
                int j=0,ans=0;
                while(j<list.size())
                {
                   ans=ans+list.get(j);
                   j+=2;
                }
                System.out.println(ans);
            }
        }
    }
}


import java.io.*;
import java.util.*;
public class SubstringRemovalGame
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0)
        {
            String s=sc.next();
            List<Integer> list=new ArrayList();
            int i=0;
            while(i<s.length())
            {
                if(s.charAt(i)=='1' && i!=s.length()-1)
                {
                    int j=i+1,count=1;
                    while(s.charAt(j)=='1')
                    {
                        count++;
                        j++;
                        if(j>s.length()-1)
                            break;
                    }
                    list.add(count);
                    i=j;
                }
                else
                    i++;
            }
            if(s.length()>=2)
            {
                if(s.charAt(s.length()-2)=='0' && s.charAt(s.length()-1)=='1')
                    list.add(1);
            }
            else
            {
                if(s.charAt(0)=='1')
                    list.add(1);
            }
            Collections.sort(list,Collections.reverseOrder());
            if(list.size()==0)
                System.out.println(0);
            else if(list.get(0)==1)
            {
                if(list.size()%2==0)
                    System.out.println((list.size()/2));
                else
                    System.out.println(((list.size()/2)+1));
            }
            else
            {
                int j=0,ans=0;
                while(j<list.size())
                {
                   ans=ans+list.get(j);
                   j+=2;
                }
                System.out.println(ans);
            }
        }
    }
}


import java.io.Writer;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.*;
import java.io.*;
import java.math.*;

public class B1398{
  static class ProblemSolver{
    public void solveTheProblem(InputReader in,OutputWriter out, NumberTheory nt){
      int test=in.nextInt();
      while(test-- >0){
        String s=in.nextLine();
        ArrayList<Integer> ar= new ArrayList<>();
        int count=0;
        for(int i=0;i<s.length();i++){
          if(s.charAt(i)=='0'){
            if(count>0) ar.add(count);
            count=0;
          }else{
            count++;
          }
        }
        if(count>0) ar.add(count);
        // System.out.println(ar);
        Collections.sort(ar, Collections.reverseOrder());
        int ans=0;
        for(int i=0;i<ar.size();i++){
          if(i%2==0) ans+=ar.get(i);
        }
        System.out.println(ans);
      }
    }
  }

  public static void main(String[] args){
    InputStream inputStream=System.in;
    OutputStream outputStream=System.out;
    InputReader in=new InputReader(inputStream);
    OutputWriter out=new OutputWriter(outputStream);
    NumberTheory nt= new NumberTheory();
    ProblemSolver problemSolver=new ProblemSolver();
    problemSolver.solveTheProblem(in,out, nt);
    out.flush();
    out.close();
  }

  static class InputReader {
    private boolean finished = false;

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public int read() {
      if (numChars == -1) {
        throw new InputMismatchException();
      }
      if (curChar >= numChars) {
        curChar = 0;
        try {
          numChars = stream.read(buf);
        } catch (IOException e) {
          throw new InputMismatchException();
        }
        if (numChars <= 0) {
          return -1;
        }
      }
      return buf[curChar++];
    }

    public int peek() {
      if (numChars == -1) {
        return -1;
      }
      if (curChar >= numChars) {
        curChar = 0;
        try {
          numChars = stream.read(buf);
        } catch (IOException e) {
          return -1;
        }
        if (numChars <= 0) {
          return -1;
        }
      }
      return buf[curChar];
    }

    public int nextInt() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      int sgn = 1;
      if (c == '-') {
        sgn = -1;
        c = read();
      }
      int res = 0;
      do {
        if (c < '0' || c > '9') {
          throw new InputMismatchException();
        }
        res *= 10;
        res += c - '0';
        c = read();
      } while (!isSpaceChar(c));
      return res * sgn;
    }

    public long nextLong() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      int sgn = 1;
      if (c == '-') {
        sgn = -1;
        c = read();
      }
      long res = 0;
      do {
        if (c < '0' || c > '9') {
          throw new InputMismatchException();
        }
        res *= 10;
        res += c - '0';
        c = read();
      } while (!isSpaceChar(c));
      return res * sgn;
    }

    public String nextLine() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      StringBuilder res = new StringBuilder();
      do {
        if (Character.isValidCodePoint(c)) {
          res.appendCodePoint(c);
        }
        c = read();
      } while (!isSpaceChar(c));
      return res.toString();
    }

    public boolean isSpaceChar(int c) {
      if (filter != null) {
        return filter.isSpaceChar(c);
      }
      return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
      return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    private String readLine0() {
      StringBuilder buf = new StringBuilder();
      int c = read();
      while (c != '\n' && c != -1) {
        if (c != '\r') {
          buf.appendCodePoint(c);
        }
        c = read();
      }
      return buf.toString();
    }

    public String readLine() {
      String s = readLine0();
      while (s.trim().length() == 0) {
        s = readLine0();
      }
      return s;
    }

    public String readLine(boolean ignoreEmptyLines) {
      if (ignoreEmptyLines) {
        return readLine();
      } else {
        return readLine0();
      }
    }

    public BigInteger readBigInteger() {
      try {
        return new BigInteger(nextLine());
      } catch (NumberFormatException e) {
        throw new InputMismatchException();
      }
    }

    public char nextCharacter() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      return (char) c;
    }

    public double nextDouble() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      int sgn = 1;
      if (c == '-') {
        sgn = -1;
        c = read();
      }
      double res = 0;
      while (!isSpaceChar(c) && c != '.') {
        if (c == 'e' || c == 'E') {
          return res * Math.pow(10, nextInt());
        }
        if (c < '0' || c > '9') {
          throw new InputMismatchException();
        }
        res *= 10;
        res += c - '0';
        c = read();
      }
      if (c == '.') {
        c = read();
        double m = 1;
        while (!isSpaceChar(c)) {
          if (c == 'e' || c == 'E') {
            return res * Math.pow(10, nextInt());
          }
          if (c < '0' || c > '9') {
            throw new InputMismatchException();
          }
          m /= 10;
          res += (c - '0') * m;
          c = read();
        }
      }
      return res * sgn;
    }

    public boolean isExhausted() {
      int value;
      while (isSpaceChar(value = peek()) && value != -1) {
        read();
      }
      return value == -1;
    }

    public String next() {
      return nextLine();
    }

    public SpaceCharFilter getFilter() {
      return filter;
    }

    public void setFilter(SpaceCharFilter filter) {
      this.filter = filter;
    }

    public interface SpaceCharFilter {
      public boolean isSpaceChar(int ch);
    }
    public int[] nextIntArray(int n){
      int[] array=new int[n];
      for(int i=0;i<n;++i)array[i]=nextInt();
      return array;
    }
    public int[] nextSortedIntArray(int n){
      int array[]=nextIntArray(n);
      Arrays.sort(array);
      return array;
    }
    public ArrayList<Integer> nextIntArrayList(int n){
      ArrayList<Integer> ar= new ArrayList<>();
      for(int i=0;i<n;i++)
        ar.add(nextInt());
      return ar;
    }
		public ArrayList<Long> nextLongArrayList(int n){
      ArrayList<Long> ar= new ArrayList<>();
      for(int i=0;i<n;i++)
        ar.add(nextLong());
      return ar;
    }

    public int[] nextSumIntArray(int n){
      int[] array=new int[n];
      array[0]=nextInt();
      for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
      return array;
    }
    public long[] nextLongArray(int n){
      long[] array=new long[n];
      for(int i=0;i<n;++i)array[i]=nextLong();
      return array;
    }
    public long[] nextSumLongArray(int n){
      long[] array=new long[n];
      array[0]=nextInt();
      for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
      return array;
    }
    public long[] nextSortedLongArray(int n){
      long array[]=nextLongArray(n);
      Arrays.sort(array);
      return array;
    }
    public int[][] nextIntMatrix(int n,int m){
      int[][] matrix=new int[n][m];
      for(int i=0;i<n;++i)
      for(int j=0;j<m;++j)
      matrix[i][j]=nextInt();
      return matrix;
    }

    public int[][] nextIntMatrix(int n){
      return nextIntMatrix(n,n);
    }

    public long[][] nextLongMatrix(int n,int m){
      long[][] matrix=new long[n][m];
      for(int i=0;i<n;++i)
      for(int j=0;j<m;++j)
      matrix[i][j]=nextLong();
      return matrix;
    }

    public long[][] nextLongMatrix(int n){
      return nextLongMatrix(n,n);
    }

    public char[][] nextCharMatrix(int n,int m){
      char[][] matrix=new char[n][m];
      for(int i=0;i<n;++i)
      matrix[i]=next().toCharArray();
      return matrix;
    }

    public char[][] nextCharMatrix(int n){
      return nextCharMatrix(n,n);
    }
  }

  static class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
      writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
      this.writer = new PrintWriter(writer);
    }

    // public void print(char[] array) {
    //     writer.print(array);
    // }

    public void print(Object... objects) {
      for (int i = 0; i < objects.length; i++) {
        if (i != 0) {
          writer.print(' ');
        }
        writer.print(objects[i]);
      }
    }

    public void print(int[] array) {
      for (int i = 0; i < array.length; i++) {
        if (i != 0) {
          writer.print(' ');
        }
        writer.print(array[i]);
      }
    }

    public void print(double[] array) {
      for (int i = 0; i < array.length; i++) {
        if (i != 0) {
          writer.print(' ');
        }
        writer.print(array[i]);
      }
    }

    public void print(long[] array) {
      for (int i = 0; i < array.length; i++) {
        if (i != 0) {
          writer.print(' ');
        }
        writer.print(array[i]);
      }
    }

    public void print(char[] array) {
      for (int i = 0; i < array.length; i++) {
        if (i != 0) {
          writer.print(' ');
        }
        writer.print(array[i]);
      }
    }

    public void print(String[] array) {
      for (int i = 0; i < array.length; i++) {
        if (i != 0) {
          writer.print(' ');
        }
        writer.print(array[i]);
      }
    }

    public void print(int[][] matrix){
      for(int i=0;i<matrix.length;++i){
        println(matrix[i]);
      }
    }

    public void print(double[][] matrix){
      for(int i=0;i<matrix.length;++i){
        println(matrix[i]);
      }
    }

    public void print(long[][] matrix){
      for(int i=0;i<matrix.length;++i){
        println(matrix[i]);
      }
    }

    public void print(char[][] matrix){
      for(int i=0;i<matrix.length;++i){
        println(matrix[i]);
      }
    }

    public void print(String[][] matrix){
      for(int i=0;i<matrix.length;++i){
        println(matrix[i]);
      }
    }

    public void println(int[] array) {
      print(array);
      writer.println();
    }

    public void println(double[] array) {
      print(array);
      writer.println();
    }

    public void println(long[] array) {
      print(array);
      writer.println();
    }

    // public void println(char[] array) {
    //     print(array);
    //     writer.println();
    // }

    public void println(String[] array) {
      print(array);
      writer.println();
    }

    public void println() {
      writer.println();
    }

    public void println(Object... objects) {
      print(objects);
      writer.println();
    }

    public void print(char i) {
      writer.print(i);
    }

    public void println(char i) {
      writer.println(i);
    }

    public void println(char[] array) {
      writer.println(array);
    }

    public void printf(String format, Object... objects) {
      writer.printf(format, objects);
    }

    public void close() {
      writer.close();
    }

    public void flush() {
      writer.flush();
    }

    public void print(long i) {
      writer.print(i);
    }

    public void println(long i) {
      writer.println(i);
    }

    public void print(int i) {
      writer.print(i);
    }

    public void println(int i) {
      writer.println(i);
    }

    public void separateLines(int[] array) {
      for (int i : array) {
        println(i);
      }
    }
  }
  static class NumberTheory{

      /**
       * Modular Arithmetic:
       *  1. (a+b)%c=(a%c+b%c)%c
       *  2. (a*b)%c=(a%c*b%c)%c
       *  3. (a-b)%c=(a%c-b%c+c)%c
       *  4. (a/b)%c=(a%c*(b^-1)%c)%c -- (b^-1 is multiplicative modulo inverse)
       */
      //Modular Addition
      public int modularAddition(int a,int b,int MOD){
          return (a%MOD+b%MOD)%MOD;
      }
      public long modularAddition(long a,long b,long MOD){
          return (a%MOD+b%MOD)%MOD;
      }
      //Modular Multiplication
      public int modularMultiplication(int a,int b,int MOD){
          return ((a%MOD)*(b%MOD))%MOD;
      }
      public long modularMultiplication(long a,long b,long MOD){
          return ((a%MOD)*(b%MOD))%MOD;
      }
      //Modular Subtraction
      public int modularSubtraction(int a,int b,int MOD){
          return (a%MOD-b%MOD+MOD)%MOD;
      }
      public long modularSubtraction(long a,long b,long MOD){
          return (a%MOD-b%MOD+MOD)%MOD;
      }

      /**
       * Binary Exponentiation
       */
      public int binaryExponentiation(int x,int n){
          if(n==0)return 1;
          else if(n%2==0)return binaryExponentiation(x*x,n/2);
          else return x*binaryExponentiation(x*x,(n-1)/2);
      }
      public long binaryExponentiation(long x,long n){
          long result=1;
          while(n>0){
              if(n%2==1)result*=x;
              x=x*x;
              n/=2;
          }
          return result;
      }

      /**
       * Modular Exponentiation
       */
      public int modularExponentiation(int x,int n,int MOD){
          if(n==0)return 1%MOD;
          else if(n%2==0)return modularExponentiation(modularMultiplication(x,x,MOD),n/2,MOD);
          else return modularMultiplication(x,modularExponentiation(modularMultiplication(x,x,MOD),(n-1)/2,MOD),MOD);
      }
      public long modularExponentiation(long x,long n,long MOD){
          long result=1;
          while(n>0){
              if(n%2==1)result=modularMultiplication(result,x,MOD);
              x=modularMultiplication(x,x,MOD);
              n/=2;
          }
          return result;
      }

      /**
       * Factorial of a number
       */
      public long factorials(long n){
          if(n==0)return 1;
          return n*factorials(n-1);
      }

      /**
       * Prime factors of a number
       */
      public ArrayList<Integer> distinctPrimeFactors(int n){
          ArrayList<Integer> factorials=new ArrayList<>();
          int limit=(int)Math.sqrt(n);
          if(n%2==0){
              factorials.add(2);
              while(n%2==0)n/=2;
          }
          for(int i=3;i<=limit;i+=2){
              if(n%i==0){
                  factorials.add(i);
                  while(n%i==0)n/=i;
              }
          }
          if(n>2)factorials.add(n);
          return factorials;
      }

      public ArrayList<Long> distinctPrimeFactors(long n){
          ArrayList<Long> factorials=new ArrayList<>();
          long limit=(long)Math.sqrt(n);
          if(n%2==0){
              factorials.add((long)2);
              while(n%2==0)n/=2;
          }
          for(long i=3;i<=limit;i+=2){
              if(n%i==0){
                  factorials.add(i);
                  while(n%i==0)n/=i;
              }
          }
          if(n>2)factorials.add(n);
          return factorials;
      }

      public ArrayList<Integer> primeFactors(int n){
          ArrayList<Integer> factorials=new ArrayList<>();
          int limit=(int)Math.sqrt(n);
          if(n%2==0){
              factorials.add(2);
              while(n%2==0)n/=2;
          }
          for(int i=3;i<=limit;i+=2){
              if(n%i==0){
                  factorials.add(i);
                  while(n%i==0)n/=i;
              }
          }
          if(n>2)factorials.add(n);
          return factorials;
      }

      public ArrayList<Long> primeFactors(long n){
          ArrayList<Long> factorials=new ArrayList<>();
          long limit=(long)Math.sqrt(n);
          if(n%2==0){
              factorials.add((long)2);
              while(n%2==0)n/=2;
          }
          for(long i=3;i<=limit;i+=2){
              if(n%i==0){
                  factorials.add(i);
                  while(n%i==0)n/=i;
              }
          }
          if(n>2)factorials.add(n);
          return factorials;
      }

      /**
       * Combination: nCr
       */
      //Naive version
      //(n,r)=(n-1,r-1)+(n-1,r) for r!=0 or r!=n
      //(n,0)=(n,n)=1
      public int binomialCoefficientRecursive(int n,int k){
          if(k==0 || k==n)return 1;//base case
          return binomialCoefficientRecursive(n-1,k-1)+binomialCoefficientRecursive(n-1,k);//recursion
      }

      //Dynamic Programming version(Uses bottom up approach to fill the table)
      //Time complexity: O(n*k)
      //Space complexity: O(n*k)
      public long binomialCoefficientIterative(int n,int k){
          long[][] C=new long[n+1][k+1];
          for(int i=0;i<=n;++i){
              for(int j=0;j<=Math.min(n,k);++j){
                  if(j==0 || j==i)C[i][j]=1;
                  else C[i][j]=C[i-1][j-1]+C[i-1][j];
              }
          }
          return C[n][k];
      }

      //Pascal's Triangle version(Space efficient program)
      //Time complexity: O(n*k)
      //Space complexity: O(k)
      public long nCr(int n,int r){
          int[] C=new int[r+1];
          C[0]=1;//nC0=1
          for(int i=1;i<=n;++i)
              for(int j=Math.min(i,r);j>0;--j)
                  C[j]=C[j]+C[j-1];
          return C[r];
      }

      /**
       * Catlan number:
       *  - Time complexity: O(n*n)
       *  - Auxiliary space: O(n)
       *
       *  NOTE: Time complexity could be reduced to O(n) but it is
       *        possible if and only if n is small or else there is
       *        a chance of getting an overflow. To decrease the time
       *        complexity to O(n) just remember nCr=nCn-r
       */
      public long catlanNumber(int n){
          long[] catlan=new long[n+1];
          catlan[0]=catlan[1]=1;
          for(int i=2;i<=n;++i)
              for(int j=0;j<i;++j)
                  catlan[i]+=catlan[j]*catlan[i-1-j];

          return catlan[n];
      }

      /**
       * Greatest Common Divisor(GCD)
       *  - It is also known as Highest Common Factor(HCF)
       *  - Time complexity: log(min(a,b))
       *  - Auxiliary Space: O(1)
       */
      public int gcd(int a,int b){
          if(b==0)return a;
          return gcd(b,a %b);
      }

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

      /**
       * Extended Euclid's Algorithm:
       *  - ax+by=gcd(a,b)
       *  - Time complexity:
       *  -
       */

      /**
       * Least Common Multiple(LCM):
       *  - Time complexity: log(min(a,b))
       *  - Auxiliary Space: O(1)
       */
      public long lcm(long a,long b){
          return (a*b)/gcd(a,b);
      }

  }
}
//
//                       "8,        .m8"
//                        I8Im    ,mI8"
//                        ,8I""I8,mI8m
//             "I8mm,    ,I8    I8 "I8,          ,m"
//                "I88I88I8m ,I8"   "I8""==mm ,mI8"
//        ___    ,mI8"    "8I8"      I8,  ,mI8I8"
//   .,mI8I8I8I8I88,      ,m8"      ,I8I8I8I888"
// "I8Im,       "I88,    ,8"      ,II8"     "88,
//    `"I8,        "I8, ,8"     ,I8"         "I8,
//       "I8m       "I888      ,I8"           "I8,
//         "8m        "I8      88"              "I8,
//          I8,        I8      88                 "I8,
//           88,       I8,     "I8                 "I8
//           "I8,      "I8,     "I8,                I8;.
//            "I8,      "I8,      "I8        .,mmmI8888888m,.
//              I8,      "I8,      I8,  .mI8I88"""". .. "I8888
//              "I8,      "I8      mI8I88"". . . . . .,m8"   "8
//               I8m,  __ ;I8   ,II88" . . . . .,;miI88"
//               "I88I8I88I88,,I88" . . . ,mmiiI8888"
//                ,I8". . ."I8I8". . . mi888888888"
//              ,I8 . . . .,I88I. . .i88888888888"
//             I8. . . .,mII88Ima. .i88888888888"
//            ,8"..,mI88I88I88I8Imi888888888888"
//            I8.,I8I"""        ""II88888888888
//           ;I8I8"                  ""I8888888
//           ""                         "I88888
//                                        "I888
//                                         "I88,
//                                          "I88
//                                           "88,
//                                            I88,              ______   __
//                           ______           "I88__        .mI88I88I88I88I88,
//                      .,mI88I88I88, ,mI88,   I88"""     ,mI8". . . . "I8,..8,
//                    ,I888' . . . "I88.\ "8,  I88      ,I8". . . .  / :;I8 \ 8,
//                  .mI8' . . .  / .:"I8.\ 88  "88,    ,8". . .  / .;mI8I8I8,\ 8
//                 ,I8'. . .  / . .:;,I8I8I888  I88   ,8". .  / .:mI8"'   "I8,:8
//                ,I8'. . . / . .:;,mI8"  `"I88 I88   I8. .  / .m8"         "I8I
//               ,I8 . .  / . .:;,mI8"      "I88888   88,.  / ,m8            "8'
//               I8'. .  / . .;,mI8"          "II888 ,I8I8,.,I8"
//               I8 . . / . .,mI8"              I8888888' """
//               `I8,.  / ;,mI8"                 II888
//                "I8I, /,mI8"                 __I888
//                  "I8888"                   """I88
//                    ""                         I88
//                                               I88__
//                                               I88"""
//                                               I88
//                                               I88
//                                             __I88
//                                            """I88
//                                               I88
//                                               I88
//                                               I88__
//                                               I88"""
//                                               I88
//                                        BITSY  ___  CHUCK


import java.io.Writer;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.*;
import java.io.*;
import java.math.*;

public class B1398{
  static class ProblemSolver{
    static class comp implements Comparator<Integer>{
      public int compare(Integer a, Integer b){
        return (a>b)?-1:1;
      }
    }
    public void solveTheProblem(InputReader in,OutputWriter out, NumberTheory nt){
      int test=in.nextInt();
      while(test-- >0){
        String s=in.nextLine();
        PriorityQueue<Integer> pq= new PriorityQueue<>(new comp());
        int c=0;
        for(int i=0;i<s.length();i++){
          char ch=s.charAt(i);
          if(ch=='0'){
             if(c>0) pq.add(c);
             c=0;
           }
          if(ch=='1') c++;
        }
        if(c>0) pq.add(c);
        long ans=0;
        int i=0;
        while(pq.peek()!=null){
          if(i%2==0) ans+=pq.poll();
          else pq.poll();
          i++;
        }

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

  public static void main(String[] args){
    InputStream inputStream=System.in;
    OutputStream outputStream=System.out;
    InputReader in=new InputReader(inputStream);
    OutputWriter out=new OutputWriter(outputStream);
    NumberTheory nt= new NumberTheory();
    ProblemSolver problemSolver=new ProblemSolver();
    problemSolver.solveTheProblem(in,out, nt);
    out.flush();
    out.close();
  }

  static class InputReader {
    private boolean finished = false;

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public int read() {
      if (numChars == -1) {
        throw new InputMismatchException();
      }
      if (curChar >= numChars) {
        curChar = 0;
        try {
          numChars = stream.read(buf);
        } catch (IOException e) {
          throw new InputMismatchException();
        }
        if (numChars <= 0) {
          return -1;
        }
      }
      return buf[curChar++];
    }

    public int peek() {
      if (numChars == -1) {
        return -1;
      }
      if (curChar >= numChars) {
        curChar = 0;
        try {
          numChars = stream.read(buf);
        } catch (IOException e) {
          return -1;
        }
        if (numChars <= 0) {
          return -1;
        }
      }
      return buf[curChar];
    }

    public int nextInt() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      int sgn = 1;
      if (c == '-') {
        sgn = -1;
        c = read();
      }
      int res = 0;
      do {
        if (c < '0' || c > '9') {
          throw new InputMismatchException();
        }
        res *= 10;
        res += c - '0';
        c = read();
      } while (!isSpaceChar(c));
      return res * sgn;
    }

    public long nextLong() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      int sgn = 1;
      if (c == '-') {
        sgn = -1;
        c = read();
      }
      long res = 0;
      do {
        if (c < '0' || c > '9') {
          throw new InputMismatchException();
        }
        res *= 10;
        res += c - '0';
        c = read();
      } while (!isSpaceChar(c));
      return res * sgn;
    }

    public String nextLine() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      StringBuilder res = new StringBuilder();
      do {
        if (Character.isValidCodePoint(c)) {
          res.appendCodePoint(c);
        }
        c = read();
      } while (!isSpaceChar(c));
      return res.toString();
    }

    public boolean isSpaceChar(int c) {
      if (filter != null) {
        return filter.isSpaceChar(c);
      }
      return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
      return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    private String readLine0() {
      StringBuilder buf = new StringBuilder();
      int c = read();
      while (c != '\n' && c != -1) {
        if (c != '\r') {
          buf.appendCodePoint(c);
        }
        c = read();
      }
      return buf.toString();
    }

    public String readLine() {
      String s = readLine0();
      while (s.trim().length() == 0) {
        s = readLine0();
      }
      return s;
    }

    public String readLine(boolean ignoreEmptyLines) {
      if (ignoreEmptyLines) {
        return readLine();
      } else {
        return readLine0();
      }
    }

    public BigInteger readBigInteger() {
      try {
        return new BigInteger(nextLine());
      } catch (NumberFormatException e) {
        throw new InputMismatchException();
      }
    }

    public char nextCharacter() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      return (char) c;
    }

    public double nextDouble() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      int sgn = 1;
      if (c == '-') {
        sgn = -1;
        c = read();
      }
      double res = 0;
      while (!isSpaceChar(c) && c != '.') {
        if (c == 'e' || c == 'E') {
          return res * Math.pow(10, nextInt());
        }
        if (c < '0' || c > '9') {
          throw new InputMismatchException();
        }
        res *= 10;
        res += c - '0';
        c = read();
      }
      if (c == '.') {
        c = read();
        double m = 1;
        while (!isSpaceChar(c)) {
          if (c == 'e' || c == 'E') {
            return res * Math.pow(10, nextInt());
          }
          if (c < '0' || c > '9') {
            throw new InputMismatchException();
          }
          m /= 10;
          res += (c - '0') * m;
          c = read();
        }
      }
      return res * sgn;
    }

    public boolean isExhausted() {
      int value;
      while (isSpaceChar(value = peek()) && value != -1) {
        read();
      }
      return value == -1;
    }

    public String next() {
      return nextLine();
    }

    public SpaceCharFilter getFilter() {
      return filter;
    }

    public void setFilter(SpaceCharFilter filter) {
      this.filter = filter;
    }

    public interface SpaceCharFilter {
      public boolean isSpaceChar(int ch);
    }
    public int[] nextIntArray(int n){
      int[] array=new int[n];
      for(int i=0;i<n;++i)array[i]=nextInt();
      return array;
    }
    public int[] nextSortedIntArray(int n){
      int array[]=nextIntArray(n);
      Arrays.sort(array);
      return array;
    }
    public ArrayList<Integer> nextIntArrayList(int n){
      ArrayList<Integer> ar= new ArrayList<>();
      for(int i=0;i<n;i++)
        ar.add(nextInt());
      return ar;
    }
		public ArrayList<Long> nextLongArrayList(int n){
      ArrayList<Long> ar= new ArrayList<>();
      for(int i=0;i<n;i++)
        ar.add(nextLong());
      return ar;
    }

    public int[] nextSumIntArray(int n){
      int[] array=new int[n];
      array[0]=nextInt();
      for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
      return array;
    }
    public long[] nextLongArray(int n){
      long[] array=new long[n];
      for(int i=0;i<n;++i)array[i]=nextLong();
      return array;
    }
    public long[] nextSumLongArray(int n){
      long[] array=new long[n];
      array[0]=nextInt();
      for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
      return array;
    }
    public long[] nextSortedLongArray(int n){
      long array[]=nextLongArray(n);
      Arrays.sort(array);
      return array;
    }
    public int[][] nextIntMatrix(int n,int m){
      int[][] matrix=new int[n][m];
      for(int i=0;i<n;++i)
      for(int j=0;j<m;++j)
      matrix[i][j]=nextInt();
      return matrix;
    }

    public int[][] nextIntMatrix(int n){
      return nextIntMatrix(n,n);
    }

    public long[][] nextLongMatrix(int n,int m){
      long[][] matrix=new long[n][m];
      for(int i=0;i<n;++i)
      for(int j=0;j<m;++j)
      matrix[i][j]=nextLong();
      return matrix;
    }

    public long[][] nextLongMatrix(int n){
      return nextLongMatrix(n,n);
    }

    public char[][] nextCharMatrix(int n,int m){
      char[][] matrix=new char[n][m];
      for(int i=0;i<n;++i)
      matrix[i]=next().toCharArray();
      return matrix;
    }

    public char[][] nextCharMatrix(int n){
      return nextCharMatrix(n,n);
    }
  }

  static class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
      writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
      this.writer = new PrintWriter(writer);
    }

    // public void print(char[] array) {
    //     writer.print(array);
    // }

    public void print(Object... objects) {
      for (int i = 0; i < objects.length; i++) {
        if (i != 0) {
          writer.print(' ');
        }
        writer.print(objects[i]);
      }
    }

    public void print(int[] array) {
      for (int i = 0; i < array.length; i++) {
        if (i != 0) {
          writer.print(' ');
        }
        writer.print(array[i]);
      }
    }

    public void print(double[] array) {
      for (int i = 0; i < array.length; i++) {
        if (i != 0) {
          writer.print(' ');
        }
        writer.print(array[i]);
      }
    }

    public void print(long[] array) {
      for (int i = 0; i < array.length; i++) {
        if (i != 0) {
          writer.print(' ');
        }
        writer.print(array[i]);
      }
    }

    public void print(char[] array) {
      for (int i = 0; i < array.length; i++) {
        if (i != 0) {
          writer.print(' ');
        }
        writer.print(array[i]);
      }
    }

    public void print(String[] array) {
      for (int i = 0; i < array.length; i++) {
        if (i != 0) {
          writer.print(' ');
        }
        writer.print(array[i]);
      }
    }

    public void print(int[][] matrix){
      for(int i=0;i<matrix.length;++i){
        println(matrix[i]);
      }
    }

    public void print(double[][] matrix){
      for(int i=0;i<matrix.length;++i){
        println(matrix[i]);
      }
    }

    public void print(long[][] matrix){
      for(int i=0;i<matrix.length;++i){
        println(matrix[i]);
      }
    }

    public void print(char[][] matrix){
      for(int i=0;i<matrix.length;++i){
        println(matrix[i]);
      }
    }

    public void print(String[][] matrix){
      for(int i=0;i<matrix.length;++i){
        println(matrix[i]);
      }
    }

    public void println(int[] array) {
      print(array);
      writer.println();
    }

    public void println(double[] array) {
      print(array);
      writer.println();
    }

    public void println(long[] array) {
      print(array);
      writer.println();
    }

    // public void println(char[] array) {
    //     print(array);
    //     writer.println();
    // }

    public void println(String[] array) {
      print(array);
      writer.println();
    }

    public void println() {
      writer.println();
    }

    public void println(Object... objects) {
      print(objects);
      writer.println();
    }

    public void print(char i) {
      writer.print(i);
    }

    public void println(char i) {
      writer.println(i);
    }

    public void println(char[] array) {
      writer.println(array);
    }

    public void printf(String format, Object... objects) {
      writer.printf(format, objects);
    }

    public void close() {
      writer.close();
    }

    public void flush() {
      writer.flush();
    }

    public void print(long i) {
      writer.print(i);
    }

    public void println(long i) {
      writer.println(i);
    }

    public void print(int i) {
      writer.print(i);
    }

    public void println(int i) {
      writer.println(i);
    }

    public void separateLines(int[] array) {
      for (int i : array) {
        println(i);
      }
    }
  }
  static class NumberTheory{

      /**
       * Modular Arithmetic:
       *  1. (a+b)%c=(a%c+b%c)%c
       *  2. (a*b)%c=(a%c*b%c)%c
       *  3. (a-b)%c=(a%c-b%c+c)%c
       *  4. (a/b)%c=(a%c*(b^-1)%c)%c -- (b^-1 is multiplicative modulo inverse)
       */
      //Modular Addition
      public int modularAddition(int a,int b,int MOD){
          return (a%MOD+b%MOD)%MOD;
      }
      public long modularAddition(long a,long b,long MOD){
          return (a%MOD+b%MOD)%MOD;
      }
      //Modular Multiplication
      public int modularMultiplication(int a,int b,int MOD){
          return ((a%MOD)*(b%MOD))%MOD;
      }
      public long modularMultiplication(long a,long b,long MOD){
          return ((a%MOD)*(b%MOD))%MOD;
      }
      //Modular Subtraction
      public int modularSubtraction(int a,int b,int MOD){
          return (a%MOD-b%MOD+MOD)%MOD;
      }
      public long modularSubtraction(long a,long b,long MOD){
          return (a%MOD-b%MOD+MOD)%MOD;
      }

      /**
       * Binary Exponentiation
       */
      public int binaryExponentiation(int x,int n){
          if(n==0)return 1;
          else if(n%2==0)return binaryExponentiation(x*x,n/2);
          else return x*binaryExponentiation(x*x,(n-1)/2);
      }
      public long binaryExponentiation(long x,long n){
          long result=1;
          while(n>0){
              if(n%2==1)result*=x;
              x=x*x;
              n/=2;
          }
          return result;
      }

      /**
       * Modular Exponentiation
       */
      public int modularExponentiation(int x,int n,int MOD){
          if(n==0)return 1%MOD;
          else if(n%2==0)return modularExponentiation(modularMultiplication(x,x,MOD),n/2,MOD);
          else return modularMultiplication(x,modularExponentiation(modularMultiplication(x,x,MOD),(n-1)/2,MOD),MOD);
      }
      public long modularExponentiation(long x,long n,long MOD){
          long result=1;
          while(n>0){
              if(n%2==1)result=modularMultiplication(result,x,MOD);
              x=modularMultiplication(x,x,MOD);
              n/=2;
          }
          return result;
      }

      /**
       * Factorial of a number
       */
      public long factorials(long n){
          if(n==0)return 1;
          return n*factorials(n-1);
      }

      /**
       * Prime factors of a number
       */
      public ArrayList<Integer> distinctPrimeFactors(int n){
          ArrayList<Integer> factorials=new ArrayList<>();
          int limit=(int)Math.sqrt(n);
          if(n%2==0){
              factorials.add(2);
              while(n%2==0)n/=2;
          }
          for(int i=3;i<=limit;i+=2){
              if(n%i==0){
                  factorials.add(i);
                  while(n%i==0)n/=i;
              }
          }
          if(n>2)factorials.add(n);
          return factorials;
      }

      public ArrayList<Long> distinctPrimeFactors(long n){
          ArrayList<Long> factorials=new ArrayList<>();
          long limit=(long)Math.sqrt(n);
          if(n%2==0){
              factorials.add((long)2);
              while(n%2==0)n/=2;
          }
          for(long i=3;i<=limit;i+=2){
              if(n%i==0){
                  factorials.add(i);
                  while(n%i==0)n/=i;
              }
          }
          if(n>2)factorials.add(n);
          return factorials;
      }

      public ArrayList<Integer> primeFactors(int n){
          ArrayList<Integer> factorials=new ArrayList<>();
          int limit=(int)Math.sqrt(n);
          if(n%2==0){
              factorials.add(2);
              while(n%2==0)n/=2;
          }
          for(int i=3;i<=limit;i+=2){
              if(n%i==0){
                  factorials.add(i);
                  while(n%i==0)n/=i;
              }
          }
          if(n>2)factorials.add(n);
          return factorials;
      }

      public ArrayList<Long> primeFactors(long n){
          ArrayList<Long> factorials=new ArrayList<>();
          long limit=(long)Math.sqrt(n);
          if(n%2==0){
              factorials.add((long)2);
              while(n%2==0)n/=2;
          }
          for(long i=3;i<=limit;i+=2){
              if(n%i==0){
                  factorials.add(i);
                  while(n%i==0)n/=i;
              }
          }
          if(n>2)factorials.add(n);
          return factorials;
      }

      /**
       * Combination: nCr
       */
      //Naive version
      //(n,r)=(n-1,r-1)+(n-1,r) for r!=0 or r!=n
      //(n,0)=(n,n)=1
      public int binomialCoefficientRecursive(int n,int k){
          if(k==0 || k==n)return 1;//base case
          return binomialCoefficientRecursive(n-1,k-1)+binomialCoefficientRecursive(n-1,k);//recursion
      }

      //Dynamic Programming version(Uses bottom up approach to fill the table)
      //Time complexity: O(n*k)
      //Space complexity: O(n*k)
      public long binomialCoefficientIterative(int n,int k){
          long[][] C=new long[n+1][k+1];
          for(int i=0;i<=n;++i){
              for(int j=0;j<=Math.min(n,k);++j){
                  if(j==0 || j==i)C[i][j]=1;
                  else C[i][j]=C[i-1][j-1]+C[i-1][j];
              }
          }
          return C[n][k];
      }

      //Pascal's Triangle version(Space efficient program)
      //Time complexity: O(n*k)
      //Space complexity: O(k)
      public long nCr(int n,int r){
          int[] C=new int[r+1];
          C[0]=1;//nC0=1
          for(int i=1;i<=n;++i)
              for(int j=Math.min(i,r);j>0;--j)
                  C[j]=C[j]+C[j-1];
          return C[r];
      }

      /**
       * Catlan number:
       *  - Time complexity: O(n*n)
       *  - Auxiliary space: O(n)
       *
       *  NOTE: Time complexity could be reduced to O(n) but it is
       *        possible if and only if n is small or else there is
       *        a chance of getting an overflow. To decrease the time
       *        complexity to O(n) just remember nCr=nCn-r
       */
      public long catlanNumber(int n){
          long[] catlan=new long[n+1];
          catlan[0]=catlan[1]=1;
          for(int i=2;i<=n;++i)
              for(int j=0;j<i;++j)
                  catlan[i]+=catlan[j]*catlan[i-1-j];

          return catlan[n];
      }

      /**
       * Greatest Common Divisor(GCD)
       *  - It is also known as Highest Common Factor(HCF)
       *  - Time complexity: log(min(a,b))
       *  - Auxiliary Space: O(1)
       */
      public int gcd(int a,int b){
          if(b==0)return a;
          return gcd(b,a %b);
      }

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

      /**
       * Extended Euclid's Algorithm:
       *  - ax+by=gcd(a,b)
       *  - Time complexity:
       *  -
       */

      /**
       * Least Common Multiple(LCM):
       *  - Time complexity: log(min(a,b))
       *  - Auxiliary Space: O(1)
       */
      public long lcm(long a,long b){
          return (a*b)/gcd(a,b);
      }

  }
}
//
//                       "8,        .m8"
//                        I8Im    ,mI8"
//                        ,8I""I8,mI8m
//             "I8mm,    ,I8    I8 "I8,          ,m"
//                "I88I88I8m ,I8"   "I8""==mm ,mI8"
//        ___    ,mI8"    "8I8"      I8,  ,mI8I8"
//   .,mI8I8I8I8I88,      ,m8"      ,I8I8I8I888"
// "I8Im,       "I88,    ,8"      ,II8"     "88,
//    `"I8,        "I8, ,8"     ,I8"         "I8,
//       "I8m       "I888      ,I8"           "I8,
//         "8m        "I8      88"              "I8,
//          I8,        I8      88                 "I8,
//           88,       I8,     "I8                 "I8
//           "I8,      "I8,     "I8,                I8;.
//            "I8,      "I8,      "I8        .,mmmI8888888m,.
//              I8,      "I8,      I8,  .mI8I88"""". .. "I8888
//              "I8,      "I8      mI8I88"". . . . . .,m8"   "8
//               I8m,  __ ;I8   ,II88" . . . . .,;miI88"
//               "I88I8I88I88,,I88" . . . ,mmiiI8888"
//                ,I8". . ."I8I8". . . mi888888888"
//              ,I8 . . . .,I88I. . .i88888888888"
//             I8. . . .,mII88Ima. .i88888888888"
//            ,8"..,mI88I88I88I8Imi888888888888"
//            I8.,I8I"""        ""II88888888888
//           ;I8I8"                  ""I8888888
//           ""                         "I88888
//                                        "I888
//                                         "I88,
//                                          "I88
//                                           "88,
//                                            I88,              ______   __
//                           ______           "I88__        .mI88I88I88I88I88,
//                      .,mI88I88I88, ,mI88,   I88"""     ,mI8". . . . "I8,..8,
//                    ,I888' . . . "I88.\ "8,  I88      ,I8". . . .  / :;I8 \ 8,
//                  .mI8' . . .  / .:"I8.\ 88  "88,    ,8". . .  / .;mI8I8I8,\ 8
//                 ,I8'. . .  / . .:;,I8I8I888  I88   ,8". .  / .:mI8"'   "I8,:8
//                ,I8'. . . / . .:;,mI8"  `"I88 I88   I8. .  / .m8"         "I8I
//               ,I8 . .  / . .:;,mI8"      "I88888   88,.  / ,m8            "8'
//               I8'. .  / . .;,mI8"          "II888 ,I8I8,.,I8"
//               I8 . . / . .,mI8"              I8888888' """
//               `I8,.  / ;,mI8"                 II888
//                "I8I, /,mI8"                 __I888
//                  "I8888"                   """I88
//                    ""                         I88
//                                               I88__
//                                               I88"""
//                                               I88
//                                               I88
//                                             __I88
//                                            """I88
//                                               I88
//                                               I88
//                                               I88__
//                                               I88"""
//                                               I88
//                                        BITSY  ___  CHUCK


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){
            String s = sc.next();
            System.out.println(calculate(s));
        }
        sc.close();

//        String s = "0110110011001011110101";
//        System.out.println(calculate(s));
    }

    private static int calculate(String s) {
        int ret = 0, n = s.length();
        ArrayList<Integer> arr = new ArrayList<Integer>();

        char[] cs = s.toCharArray();
        int cur = 0;

        for (int i = 0; i < n; i++) {

            while (i < n && cs[i] == '1') {
                cur++;
                i++;
            }
            if(cur!=0) arr.add(cur);

            cur = 0;
        }

        Collections.sort(arr);
        System.out.println(arr.size());

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

        return ret;
    }
}


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){
            String s = sc.next();
            System.out.println(calculate(s));
        }
        sc.close();

//        String s = "0110110011001011110101";
//        System.out.println(calculate(s));
    }

    private static int calculate(String s) {
        int ret = 0, n = s.length();
        ArrayList<Integer> arr = new ArrayList<Integer>();

        char[] cs = s.toCharArray();
        int cur = 0;

        for (int i = 0; i < n; i++) {

            while (i < n && cs[i] == '1') {
                cur++;
                i++;
            }
            if(cur!=0) arr.add(cur);

            cur = 0;
        }

        Collections.sort(arr);

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

        return ret;
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-- != 0){
       ArrayList<Integer> list = new ArrayList<Integer>();
            String s = sc.next();
             s += "x";
            int result = 0, counter = 0;
            int j = 0;
           while( j<s.length()){
                if(s.charAt(j) == '1'){
                    counter++;
                }else{

                        list.add(counter);
                    counter = 0;
                }
                j++;
            }
            Collections.sort(list);
            Collections.reverse(list);
            for(int i = 0; i<list.size(); i+=2){
               result += list.get(i);
            }
            System.out.println(result);
        }
    }
}


import java.io.BufferedReader;
import java.io.*;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
import java.math.*;
public class Main
{
    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;
        }
    }
   public static void main(String args[])
    {
        FastReader sc=new FastReader();
        PrintWriter pw=new PrintWriter(System.out);
        int t=sc.nextInt();
        while(t-->0)
        {
           String s=sc.next();
           char c[]=s.toCharArray();int k=0,ans=0;
           List<Integer> l=new ArrayList<>();
           for(int i=0;i<c.length-1;i++)
           {
               if(c[i]=='1' && c[i+1]=='1')
               {k++;}
               else if(c[i]=='1' && c[i+1]!='1')
               {
                   l.add(k+1);
                   k=0;
               }
           }l.add(k+1);
           if(s.indexOf('1')<0) pw.println(0);
           else{
           Collections.sort(l);
           for(int i=l.size()-1;i>=0;i-=2)
           ans+=l.get(i);
           pw.println(ans);
           }
        }
           pw.close();
    }
}


import java.io.BufferedReader;
import java.io.*;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
import java.math.*;
public class Main
{
    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;
        }
    }
   public static void main(String args[])
    {
        FastReader sc=new FastReader();
        PrintWriter pw=new PrintWriter(System.out);
        int t=sc.nextInt();
        while(t-->0)
        {
           String s=sc.next();
           char c[]=s.toCharArray();int k=0,ans=0;
           List<Integer> l=new ArrayList<>();
           for(int i=0;i<c.length-1;i++)
           {
               if(c[i]=='1' && c[i+1]=='1')
               {k++;}
               else if(c[i]=='1' && c[i+1]!='1')
               {
                   l.add(k+1);
                   k=0;
               }
           }
           if(c[c.length-1]=='1')
           l.add(k+1);
           if(s.indexOf('1')<0) pw.println(0);
           else{
           Collections.sort(l);
           for(int i=l.size()-1;i>=0;i-=2)
           ans+=l.get(i);
           pw.println(ans);
           }
        }
           pw.close();
    }
}


import java.io.BufferedReader;
import java.io.*;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
import java.math.*;
public class Main
{
    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;
        }
    }
   public static void main(String args[])
    {
        FastReader sc=new FastReader();
        PrintWriter pw=new PrintWriter(System.out);
        int t=sc.nextInt();
        while(t-->0)
        {
           String s=sc.next();
           char c[]=s.toCharArray();int k=0,ans=0;
           List<Integer> l=new ArrayList<>();
           for(int i=0;i<c.length-1;i++)
           {
               if(c[i]=='1' && c[i+1]=='1')
               {k++;}
               else if(c[i]=='1' && c[i+1]!='1')
               {
                   l.add(k+1);
                   k=0;
               }
           }
           if(k!=0)
           l.add(k+1);
           if(s.indexOf('1')<0) pw.println(0);
           else{
           Collections.sort(l);
           for(int i=l.size()-1;i>=0;i-=2)
           ans+=l.get(i);
           pw.println(ans);
           }
        }
           pw.close();
    }
}


import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long t = sc.nextLong();
		while(t>0){
		    String s = sc.next();
		    int len = s.length();
		    int a[] = new int[100];
		    int cnt = 0;
		    int j = 0;
		    for(int i=0;i<len;i++){
		        if(s.charAt(i)=='1'){
		            cnt++;
		        }
		        else{
		            a[j] = cnt;
		            j++;
		            cnt = 0;
		        }
		    }
		    a[j] = cnt;
		    Arrays.sort(a);
		    int fans = 0;
		    int chkcnt = 1;
		    for(int i=99;i>=0;i--){
		        if(a[i]>0){
		            if(chkcnt%2==1){
		                fans += a[i];
		            }
		            chkcnt++;
		        }
		    }
		    System.out.println(fans);

            t--;
		}
	}
}


import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long t = sc.nextLong();
		while(t>0){
		    String s = sc.next();
		    int len = s.length();
		    int a[] = new int[101];
		    int cnt = 0;
		    int j = 0;
		    for(int i=0;i<len;i++){
		        if(s.charAt(i)=='1'){
		            cnt++;
		        }
		        else{
		            a[j] = cnt;
		            j++;
		            cnt = 0;
		        }
		    }
		    a[j] = cnt;
		    Arrays.sort(a);
		    int fans = 0;
		    int chkcnt = 1;
		    for(int i=100;i>=0;i--){
		        if(a[i]>0){
		            if(chkcnt%2==1){
		                fans += a[i];
		            }
		            chkcnt++;
		        }
		    }
		    System.out.println(fans);

            t--;
		}
	}
}


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

public class Main {
    private static final boolean N_CASE = true;

    private void solve() {
        String s = sc.next();
        List<Integer> a = new ArrayList<>();
        int i = 0;
        int n = s.length();
        while (i < n) {
            if (s.charAt(i) == '1') {
                int cnt = 0;
                while (i < n && s.charAt(i) == '1') {
                    ++cnt;
                    ++i;
                }
                a.add(cnt);
            } else {
                ++i;
            }
        }

        a.sort(Collections.reverseOrder());

        int ans = 0;
        for (int k = 0; k < a.size(); k += 2) {
            ans += a.get(k);
        }
        out.println(ans);
    }

    private void run() {
        int T = N_CASE ? sc.nextInt() : 1;
        for (int t = 0; t < T; ++t) {
            solve();
        }
    }

    private static MyWriter out;
    private static MyScanner sc;

    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        private MyScanner() {
            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());
        }

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

        int[][] nextIntArray(int n, int m) {
            int[][] a = new int[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    a[i][j] = sc.nextInt();
                }
            }
            return a;
        }

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

        List<Integer> nextList(int n) {
            List<Integer> list = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                list.add(nextInt());
            }
            return list;
        }

        List<Long> nextLongList(int n) {
            List<Long> list = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                list.add(nextLong());
            }
            return list;
        }

        char[] nextCharArray(int n) {
            return sc.next().toCharArray();
        }

        char[][] nextCharArray(int n, int m) {
            char[][] c = new char[n][m];
            for (int i = 0; i < n; i++) {
                String s = sc.next();
                for (int j = 0; j < m; j++) {
                    c[i][j] = s.charAt(j);
                }
            }
            return c;
        }
    }

    private static class MyWriter extends PrintWriter {
        private MyWriter(OutputStream outputStream) {
            super(outputStream);
        }

        void printArray(int[] a) {
            for (int i = 0; i < a.length; ++i) {
                print(a[i]);
                print(i == a.length - 1 ? '\n' : ' ');
            }
        }

        void printlnArray(int[] a) {
            for (int v : a) {
                println(v);
            }
        }

        void printList(List<Integer> list) {
            for (int i = 0; i < list.size(); ++i) {
                print(list.get(i));
                print(i == list.size() - 1 ? '\n' : ' ');
            }
        }

        void printlnList(List<Integer> list) {
            list.forEach(this::println);
        }
    }

    private <T> List<List<T>> createGraph(int n) {
        List<List<T>> g = new ArrayList<>();
        for (int i = 0; i < n; ++i) {
            g.add(new ArrayList<>());
        }
        return g;
    }

    public static void main(String[] args) {
        out = new MyWriter(new BufferedOutputStream(System.out));
        sc = new MyScanner();
        new Main().run();
        out.close();
    }
}


import java.util.*;

public class S574B{

	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0){
		String s=sc.next();

	char[] ar=s.toCharArray();
	  ArrayList<Integer> al=new ArrayList<>();
	int cnt=0; boolean ok=false;
		for(int i=0;i<ar.length;i++){
		   if(ar[i]=='1'){
		       cnt++;
		       ok=false;
		   }
		   else{
		       if(cnt!=0){
		       al.add(cnt);
		           ok=true;
		       }
		       cnt=0;

		   }

		}
		if(ok==false){
		    if(cnt!=0){
		    al.add(cnt);}
		}
		if(al.size()==0){
		    System.out.println("0");
		}
		else{int ans=0;
		Collections.sort(al,Collections.reverseOrder());
		    for(int i=0;i<al.size();i++){
		        if(i%2==0){
		           ans+=al.get(i);
		        }
		    }
		    System.out.println(ans);
		}

		}

	}
}


import java.util.*;

public class A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int testCases = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        sc.nextLine();
        for (int t = 0; t < testCases; t++) {
            String str = sc.nextLine();
            char c[] = str.toCharArray();

            LinkedList<Integer> al = new LinkedList<>();
            int n = c.length;
            int count = 0;
            char prev = '1';
            for (int i = 0; i < n; i++) {
                if (i == 0) {
                    prev = c[i];
                    count++;
                    continue;
                }
                if (prev == c[i]) {
                    count++;
                    if (i == n - 1 && prev != '0') {
                        al.add(count);
                    }
                } else {
                    if (prev != '0')
                        al.add(count);
                    prev = c[i];
                    count = 1;
                    if (i == n - 1 && prev != '0') {
                        al.add(count);
                    }
                }
            }
            Collections.sort(al, Collections.reverseOrder());
            long alScore = 0;
            while (!al.isEmpty()) {
                alScore += al.remove(0);
                if (!al.isEmpty()) {
                    al.remove(0);
                }
            }
            sb.append(alScore).append("\n");
        }
        System.out.print(sb);
    }
}


import java.util.*;

public class A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int testCases = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        sc.nextLine();
        for (int t = 0; t < testCases; t++) {
            String str = sc.nextLine();
            char c[] = str.toCharArray();

            LinkedList<Integer> al = new LinkedList<>();
            int n = c.length;
            int count = 0;
            char prev = '1';
            for (int i = 0; i < n; i++) {
                if (i == 0) {
                    prev = c[i];
                    count++;
                    if (i == n - 1 && prev != '0') {
                        al.add(count);
                    }
                    continue;
                }
                if (prev == c[i]) {
                    count++;
                    if (i == n - 1 && prev != '0') {
                        al.add(count);
                    }
                } else {
                    if (prev != '0')
                        al.add(count);
                    prev = c[i];
                    count = 1;
                    if (i == n - 1 && prev != '0') {
                        al.add(count);
                    }
                }
            }
            Collections.sort(al, Collections.reverseOrder());
            long alScore = 0;
            while (!al.isEmpty()) {
                alScore += al.remove(0);
                if (!al.isEmpty()) {
                    al.remove(0);
                }
            }
            sb.append(alScore).append("\n");
        }
        System.out.print(sb);
    }
}


// package Contest;
import java.io.*;
import java.util.*;
import java.math.*;
import java.util.regex.*;

public class A {

static class Pair<E, V> implements Comparable<Pair<E, V>>{
       E a;
       V b;
       public Pair(E x, V y) {a = x;b=y;}
       public int compareTo(Pair<E, V> p){
           return Integer.compare((Integer)a, (Integer)p.a);
       }
        @Override
        public int hashCode() {
            final int prime = 31;
            int result = 1;
            result = prime * result + (Integer)a;
            result = prime * result + (Integer)b;

            return result;
        }
        @Override
        public boolean equals(Object obj) {
            Pair<E, V> cur = (Pair<E, V>)obj;
            if((Integer)a == (Integer)cur.a && (Integer)b == (Integer)cur.b)return true;
            if((Integer)b == (Integer)cur.a && (Integer)a == (Integer)cur.b)return true;
            return false;
        }
 }
public static void main(String[] args) throws Exception {
   new Thread(null, null, "Anshum Gupta", 99999999) {
        public void run() {
            try {
                solve();
            } catch(Exception e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    }.start();
}
public static long gcd(long a,long b)
{
  if(a<b)
    return gcd(b,a);
  if(b==0)
    return a;
  return gcd(b,a%b);

}
static long lcm(int a,int b) {
  return  a*b / gcd(a,b);
}
static int[] z(char[]arr) {
    int l = 0, r = 0;
    int[]z = new int[n];
    for(int i=1; i<n; i++) {
        if(i > r) {
            l = r = i;
            while(r < n && arr[r-l] == arr[r])r++;
            z[i] = r-- - l;
        }else {
            int k = i - l;
            if(z[k] < r - i + l)z[i] = z[k];
            else {
                l = i;
                while(r < n && arr[r-l] == arr[r])r++;
                z[i] = r-- - l;
            }
        }
    }
    return z;
}
static long pow(long x,long y){
    if(y == 0)return 1;
    if(y==1)return x;
    long a = pow(x,y/2);
    a = (a*a)%mod;
    if(y%2==0){
        return a;
    }
    return (a*x)%mod;
}
static long my_inv(long a) {
    return pow(a,mod-2);
}
static long bin(int a,int b) {
    if(a < b || a<0 || b<0)return 0;
    return ((fact[a]*inv_fact[a-b])%mod * inv_fact[b])%mod;
}
static void make_facts() {
  fact=new long[mxN];
  inv_fact = new long[mxN];
  fact[0]=inv_fact[0]=1L;
  for(int i=1;i<mxN;i++) {
       fact[i] = (i*fact[i-1])%mod;
       inv_fact[i] = my_inv(fact[i]);
  }
}
static final long mxx = (long)(1e18+5);
static final int mxN = (int)(1e5);
static final int mxV = (int)(1e5+5), log = 18;
static long mod = (long)(1e9+7); //998244353;//
static int[]tree, lazy, dep;
static long[]fact, inv_fact;
static final int INF = (int)1e9+5;
static boolean[]vis;
static ArrayList<ArrayList<Integer>> adj;
static int n, m, k, x, y, z, q;
static char[] str;
static int[]a;
static StringBuilder sb;
static int move() {
	String str = sb.toString();
	int oc = 0;
	for(int i=0; i<str.length(); i++) {
		if(str.charAt(i) == '1')oc++;
	}
	if(oc == 0) {
		sb = new StringBuilder("");
//		out.println("hello");
		return 0;
	}else {
		int ans = 0;
		int ml = 0, st = -1;
		for(int i=0; i<str.length(); i++) {
			int j = i;
			int cnt = 0;
			while(j < str.length() && str.charAt(j) == '1') {
				j++;
				cnt++;
			}
			if(cnt > ml) {
				ml = cnt;
				st = i;
			}
			if(j > i) {
				i = j - 1;
			}
		}
		assert(st >= 0);
		sb.delete(st, st + ml);
//		out.println(sb.toString());
		return ml;
	}
}
	public static void solve() throws Exception {
	   // solve the problem here
			s = new MyScanner();
	   		out = new PrintWriter(new BufferedOutputStream(System.out), true);
//	   		out = new PrintWriter("output.txt");
	        int tc = s.nextInt();
	        while(tc-->0){
	        	String str = s.next();//toCharArray();
	        	sb = new StringBuilder(str);
	        	int cnt = 0, turn = 0;
//	        	move();
	        	while(sb.toString().length() > 0) {
	        		if(turn % 2 == 0) {
	        			cnt += move();
	        		}else move();
	        		turn ^= 1;
//	        		out.println(cnt);
	        	}
	        	out.println(cnt);
	        }

	        out.flush();
	        out.close();
	}

public static PrintWriter out;
public static MyScanner s;
static class MyScanner {

    BufferedReader br;
    StringTokenizer st;

    public MyScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    public MyScanner(String fileName) {
    	try {
			br = new BufferedReader(new FileReader(fileName));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
    }
    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()); }
    int[] nextIntArray(int n){
    	int[]a = new int[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextInt();
    	}
    	return a;
    }
    long[] nextlongArray(int n) {
    	long[]a = new long[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextLong();
    	}
    	return a;
    }
    Integer[] nextIntegerArray(int n){
    	Integer[]a = new Integer[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextInt();
    	}
    	return a;
    }
    Long[] nextLongArray(int n) {
    	Long[]a = new Long[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextLong();
    	}
    	return a;
    }
    char[][] next2DCharArray(int n, int m){
    	char[][]arr = new char[n][m];
    	for(int i=0; i<n; i++) {
    		arr[i] = this.next().toCharArray();
    	}
    	return arr;
    }
    ArrayList<ArrayList<Integer>> readUndirectedUnweightedGraph(int n, int m) {
    	ArrayList<ArrayList<Integer>>adj = new ArrayList<ArrayList<Integer>>();
    	for(int i=0; i<=n; i++)adj.add(new ArrayList<Integer>());
    	for(int i=0; i<m; i++) {
    		int u = s.nextInt();
    		int v = s.nextInt();
    		adj.get(u).add(v);
    		adj.get(v).add(u);
    	}
    	return adj;
    }
    ArrayList<ArrayList<Integer>> readDirectedUnweightedGraph(int n, int m) {
    	ArrayList<ArrayList<Integer>>adj = new ArrayList<ArrayList<Integer>>();
    	for(int i=0; i<=n; i++)adj.add(new ArrayList<Integer>());
    	for(int i=0; i<m; i++) {
    		int u = s.nextInt();
    		int v = s.nextInt();
    		adj.get(u).add(v);
    	}
    	return adj;
    }
    String nextLine(){
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}

}