#include <iostream>
#define forn(n, i) for(int i = 0; i < (n); i++)
using namespace std;

int *G, L = 12;

int get_moves(int g, int *M)
{
    int mask=7, a = 6, b = 3;

    int r = 0;
    forn(L-2, i)
    {
        int c = (g >> i) & mask;
        if (c == a)
            M[r++] = g - (1 << i) * 5;
        if (c == b)
            M[r++] = g + (1 << i);
    }
    return r;
}

void do_game(int g)
{
    int M[L];
    int M_len = get_moves(g, M);

    int max = 0;
    forn(M_len, i)
    {
        int m = M[i];
        if (G[m] > L)
            do_game(m);
        
        if (G[m] > max)
            max = G[m];
    }

    if (M_len == 0)
        G[g] = 0;
    else
        G[g] = max + 1;
}

int main()
{
    char line[L + 2];
    G = new int[1 << L];
    forn(1 << L, i)
        G[i] = L+1;

    int n_games;
    cin >> n_games;

    forn(n_games, i)
    {
        int g = 0;
        cin >> line;
        forn(L, j)
        {
            g <<= 1;
            g += line[j]=='o';
        }

        do_game(g);

        int r = -G[g];
        forn(L, j)
            if (g & (1 << j))
                r++;
        cout << r << endl;
    }

    delete[] G;
    return 0;
}
