// Original C++ solution (slower):
#include <functional>

#include <algorithm>

#include <iostream>

#include <numeric>

#include <iomanip>

#include <utility>

#include <cstdlib>

#include <sstream>

#include <bitset>

#include <vector>

#include <cstdio>

#include <ctime>

#include <queue>

#include <deque>

#include <cmath>

#include <stack>

#include <list>

#include <map>

#include <set>



using namespace std;



typedef vector<int> vi;

typedef pair<int,int> pii;

typedef long long ll;



#define dump(x)  cerr << #x << " = " << (x) << endl

#define rep(i,n) for(int i=0;i<(n);i++)

#define REP(i,m,n) for(int i=(m);i<(n);i++)

#define ALL(a)  (a).begin(),(a).end()

#define pb push_back

#define sz size()







string pre(string s){   // "][" を空白に置き換え

    string b="";

    rep(i,s.sz-1){

        if(s[i]==']' && s[i+1]=='['){

            b+=' ';

            i++;

        }

        else{

            b+=s[i];

        }

    }

    b+=s[s.sz-1];

    return b;

}





string solve(int n,bool check,string s){

    n++;

    string tmp[10000]={};



    int count=0;

    REP(j,n,s.sz){

        if(s[j]!=']'){

            if(s[j]!=' '){

                tmp[count]+=s[j];

            }

            else{

                count++;

            }

        }

        else break;

    }

    vi a;

    rep(i,count+1){

        a.pb(stoi(tmp[i]));

    }

    sort(ALL(a));

    

    int sum=0;

    rep(i,count/2+1){

        if(check==false)

            sum+=a[i]/2+1;

        else

            sum+=a[i];

    }

    return to_string((sum));

}





string delSpace(string s){  // "] [" を "][" に置き換え

    string ret="";

    rep(i,s.sz-2){

        if(s[i]==']' && s[i+1]==' ' && s[i+2]=='['){

            ret+="][";

            i+=2;

        }

        else{

            ret+=s[i];

        }

    }

    ret+=s[s.sz-2];

    ret+=s[s.sz-1];

    return ret;

}





int main(){

    int t;

    cin>>t;

    

    rep(times,t){

        string s;

        cin>>s;

        int check=false;

        s=pre(s);

        while(1){

            if(s.find("[",0)==-1)break;



            string n="";

    

            rep(i,s.sz){

                if(s[i+1]>='0' && s[i+1]<='9'){

                    n+=solve(i,check,s);

                    while(s[i]!=']')i++;

                }

                else{

                    n+=s[i];

                }

            }

            s=n;

            check=true;

        }

        cout<<s<<endl;

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

typedef pair<int,int> pii;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)

#define all(a)  (a).begin(),(a).end()

#define pb push_back

#define INF (1e9+1)



typedef string::const_iterator State;





int number(State &begin){

	int ret = 0;

	while(isdigit(*begin)){

		ret*=10;

		ret+=*begin-'0';

		begin++;

	}

	return (ret+1)/2;

}





int exp(State &begin){

	begin++;

	if(isdigit(*begin)){

		int ret = number(begin);

		begin++;

		return ret;

	}

	else{

		vector<int> res;

		while(*begin=='['){

			int t = exp(begin);

			res.pb(t);

		}

		begin++;

		

		int ret=0;

		sort(all(res));

		rep(i,(res.size()+1)/2)ret+=res[i];

		return ret;

	}

}





int main(){

	int n;

	cin>>n;

	while(n--){

		string s;

		cin>>s;

		State begin = s.begin();

		cout<<exp(begin)<<endl;

	}

}

// Fastest known solution for this problem:
#include <bits/stdc++.h>



using namespace std;



#define LOG(...) fprintf(stderr, __VA_ARGS__)

//#define LOG(...)

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)

#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)

#define ALL(a) (a).begin(), (a).end()

#define RALL(a) (a).rbegin(), (a).rend()

#define EXIST(s, e) ((s).find(e) != (s).end())

#define SORT(c) sort(ALL(c))

#define RSORT(c) sort(RALL(c))

#define SZ(a) ((int)(a).size())

#define BIT(x, i) (((x) >> (i)) & 1)

#define SQ(x) ((x) * (x))



typedef long long ll;

typedef unsigned long long ull;

typedef vector<bool> vb;

typedef vector<int> vi;

typedef vector<ll> vll;

typedef vector<vb> vvb;

typedef vector<vi> vvi;

typedef vector<vll> vvll;

typedef vector<char> vc;

typedef vector<vc> vvc;

typedef vector<string> vs;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;



int dfs(string& s, int& idx) {

    vi N;

//    LOG("%s (%d)\n  ->", s.c_str()+idx, idx);

    for (; idx < s.length();) {

        if (s[idx] == '[') {

            idx++;

            N.push_back(dfs(s, idx));

        } else if (s[idx] == ']') {

            idx++;

            SORT(N);

            return accumulate(N.begin(), N.begin()+SZ(N)/2+1, 0);

        } else {

            int n = 0;

            while (isdigit(s[idx])) {

                n *= 10;

                n += s[idx] - '0';

                idx++;

            }

            idx++;

            return n/2+1;

        }

    }

    return N[0];

}



int main() {

    int n;

    cin >> n;

    REP(_i, n) {

        string s;

        cin >> s;

        int idx = 0;

        cout << dfs(s, idx) << endl;

    }

}