#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
string s;
int n,i;
int f()
{
	i++;
	vector<int>a;
	while(s[i]=='[')a.push_back(f()),i++;
	if(s[i]>='0'&&s[i]<='9')
	{
		int now=0;
		while(s[i]>='0'&&s[i]<='9')now=now*10+s[i]-'0',i++;
		now=now/2+1;
		a.push_back(now);
	}
	int ans=0;
	sort(a.begin(),a.end());
	for(int j=0;j<=(a.size()-1)/2;j++)ans+=a[j];
	return ans;
}
int main()
{
	cin>>n;
	while(n--)
	{
		cin>>s;
		i=0;
		cout<<f()<<endl;
	}
}

