#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<(int)N;i++)
#define ck(n,a,b) ((a)<=(n)&&(n)<(b))
#define p(s) cout<<(s)<<endl
#define F first
#define S second
typedef long long ll;
using namespace std;

int ind, N;
string S;

ll dfs(){
	if(S[ind] == '['){
		vector<ll> v;
		ind++;
		while(1){
			if(S[ind] == ']') break;
			v.push_back(dfs());
		}
		ind++;
		sort(v.begin(), v.end());
		ll ret = 0;
		REP(i,0,v.size()/2 + 1) ret += v[i];
		return ret;
	}else if(isdigit(S[ind])){
		ll ret = 0;
		while(isdigit(S[ind])){
			//cout<<"---"<<S[ind]<<endl;
			ret = ret*10LL + (ll)(S[ind] - '0');
			//cout<<"> "<<ret<<endl;
			ind++;
		}
		//cout<<"prev_ret: "<<ret<<endl;
		ret = ret/2+1;
		//cout<<"ret: "<<ret<<endl;
		return ret;
	}
	return 999999999;
}

int main() {
	cin>>N;
	REP(i,0,N){
		cin>>S;
		ind = 0;
		cout<<dfs()<<endl;
	}
	return 0;
}