#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

ll pos,len;
char s[10010];

ll f(){
	if(s[pos]!='['){
		ll temp=atoi(s+pos);
		pos=strchr(s+pos,']')-s+1;
		return temp/2+1;
	}
	ll a[4000]={},acnt=0;
	while(pos<len&&s[pos]!=']'){
		pos++;
		a[acnt++]=f();
	}
	pos++;
	sortup(a,acnt);
	ll ans=0;
	rep(i,0,acnt/2+1)ans+=a[i];
	return ans;
}

int main(){
	ll n;
	scanf("%lld",&n);
	while(n--){
		scanf(" %s",s);
		len=strlen(s);
		pos=0;
		printf("%lld\n",f());
	}
}
