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

string st;
int a;
int getnum() {
	int num = 0;
	while (1) {
		if (st[a] == ']') {
			return num/2+1;
		}
		else {
			num *= 10;
			num += st[a] - '0';
			a++;
		}
	}

}

int getans() {
	vector<int>nums;
	while (1) {

		if (st[a] == '[') {
			a++;
			nums.push_back(getans());
		}
		else if (st[a] == ']') {
			sort(nums.begin(), nums.end());
			int ans = 0;
			for (int i = 0; i < nums.size() / 2 + 1; ++i) {
				ans += nums[i];
			}
			a++;
			return ans;
		}
		else {
			nums.push_back(getnum());
		}
	}
}

int main() {
	int n; cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> st;
		a = 1;
		const int ans(getans());
		cout << ans << endl;
	}
	return 0;
}