#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

string s;
int p = 0;

bool is_digit(char c){
	return '0' <= c && c <= '9';
}

int dfs(){
	vector<int> v;
	while( p < s.size() ){
		if( is_digit(s[p]) ){
			int res = 0;
			while( is_digit(s[p]) ){
				res *= 10;
				res += s[p] - '0';
				p++;
			}
			v.push_back((res + 1) / 2);
		}else if( s[p] == '[' ){
			p++;
			v.push_back( dfs() );
		}else if( s[p] == ']' ){
			p++;
			int n = v.size();
			vector<int> a = v;
			sort(a.begin(), a.end());
			int res = 0;
			for(int i = 0; i <= n/2; i++){
				res += a[i];
			}
			return res;
		}
	}
}

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s;
		p = 1;
		cout << dfs() << endl;
	}
}