#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
string s;
int i;
int func(int a){
	vector<int>in;
	for(i=a;i<1e10;i++){
		if(s[i]==']')break;
		if(s[i]=='['){
			int q=i+1;
			in.pb(func(q));
		}
		if(isdigit(s[i])){
			int out=0;//s[i]-'0';
			while(isdigit(s[i])){
				out*=10;
				out+=s[i]-'0';
				i++;
			}
			return out/2+1;
		}
	}
	//rep(j,in.size())cout<<" "<<in[j];
	//cout<<endl;

	sort(all(in));
	int sum=0;
	rep(j,in.size()/2+1)sum+=in[j];
	return sum;
}
int main(){
	int n;
	cin>>n;
	while(n--){
		i=0;
		cin>>s;
		int q=1;
		cout<<func(q)<<endl;
	}
}