#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
char str[11000];
vector<int>li[10000];
int cur;
int calc(int a){
	//printf("%d %d\n",a,cur);fflush(stdout);
	int ret=0;
	if(str[cur]>='0'&&str[cur]<='9'){
		while(str[cur]>='0'&&str[cur]<='9'){
			ret*=10;
			ret+=str[cur]-'0';
			cur++;
		}
		return (ret+1)/2;
	}
	li[a].clear();
	while(str[cur]=='['){
		cur++;
		li[a].push_back(calc(a+1));
		cur++;
	}
	std::sort(li[a].begin(),li[a].end());
	for(int i=0;i<(li[a].size()+1)/2;i++)ret+=li[a][i];
	return ret;
}
int main(){
	int a;
	scanf("%d",&a);
	while(a--){
		scanf("%s",str);
		cur=0;
		printf("%d\n",calc(0));
	}
}