import java.util.Scanner;

public class Main
{
	static int[] data;

	static void calculate(int case_id)
	{
		if (data[case_id] != 0) return;
		int min = 12;
		int num_pebbles = 0;
		for (int i = 0; i < 12; i++)
		{
			if ((case_id & (1 << i)) == 0) continue;
			num_pebbles++;
			if (i >= 2 && (case_id & (1 << (i - 2))) == 0 && (case_id & (1 << (i - 1))) > 0)
			{

				int new_state = case_id + (1 << (i - 2)) - (1 << i) - (1 << (i - 1));
				calculate(new_state);
				min = data[new_state] < min ? data[new_state] : min;
			}
			if (i < 10 && (case_id & (1 << (i + 2))) == 0 && (case_id & (1 << (i + 1))) > 0)
			{
				int new_state = case_id + (1 << (i + 2)) - (1 << i) - (1 << (i + 1));
				calculate(new_state);
				min = data[new_state] < min ? data[new_state] : min;
			}
		}
		min = min < num_pebbles ? min : num_pebbles;
		data[case_id] = min;
	}

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

		int num_cases;
		num_cases = in.nextInt();
		in.nextLine();

		data = new int[4096];

		for (int i = 0; i < num_cases; i++)
		{
			String case_str = in.nextLine();
			int case_id = 0;
			for (int j = 0; j < 12; j++)
			{
				char c = case_str.charAt(j);
				if (c == '-') continue;
				case_id = case_id | (1 << j);
			}

			calculate(case_id);
			int min = data[case_id];

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