#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)

string str;

int parse(int lft, int rgt) {
	int k = 0, nxl = -1, num = 0;
	priority_queue< int, vector< int >, greater< int > > que;
	
	for_(i,lft,rgt) {
		if (str[i] == '[') {
			if (k == 0) nxl = i+1;
			++k;
		}
		
		if (k > 0 && str[i] == ']') {
			--k;
			if (k == 0) que.push(parse(nxl, i));
		}
		
		if (k == 0 && isdigit(str[i])) {
			num = 10 * num + (str[i] - '0');
		}
	}
	
	if (num != 0) return num / 2 + 1;
	
	int qsize = (int)que.size();	
	int res = 0;
	
	for_(i,0,qsize/2 + 1) {
		res += que.top();
		que.pop();
	}
	
	return res;
}

int main() {
	int T;
	cin >> T;
	
	for_(i,0,T) {
		cin >> str;
		cout << parse(0, (int)str.size()) << endl;		
	}
}