#include<iostream>
#include<algorithm>
#include<string>
#include<stack>
#include<cstdlib>
using namespace std;

int main(){
	int n;
	string set;
	stack<int> st[2000];
	
	cin >> n;
	while(n > 0){
		int count = 0;
		string val;
		cin >> set;
		for(int i=0; i<set.length(); i++){
			if(set[i] == '['){
				count++;
			}else if(set[i-1] == ']' && set[i] == ']'){
				int tmp[5000],sum=0,stsize,p=0;;
				stsize = st[count+1].size();
				while(!st[count+1].empty() ){
					tmp[p++] = st[count+1].top();
					st[count+1].pop();
				}
				sort(tmp, tmp+stsize);
				for(int j=0; j<(stsize+1)/2; j++){
					sum += tmp[j];
				}
				st[count].push(sum);
				count--;
			}else if(set[i] == ']'){
				st[count].push( (atoi(val.c_str())+1)/2 );
				count--;
			}else{
				int beg=i;
				while(set[i+1] != ']'){
					i++;
				}
				val = set.substr(beg, i-beg+1);
			}
		}
		cout << st[1].top() << endl;
		n--;
	}
}