#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;
	}
}