#include <bits/stdc++.h>

using namespace std;

string s;
int N;

int main() {
  cin >> N;
  while ( N-- ) {
    cin >> s;
    vector<int> data[10000];
    int now = 0;
    for ( int i = 0; i < s.size(); i++ ) {
      if ( s[i] == '[' ) now++;
      else if ( s[i] == ']' ) {
	if ( data[now].size() ) {
	  sort(data[now].begin(), data[now].end());
	  int tmp = 0;
	  for ( int j = 0; j < (data[now].size() + 1) / 2; j++ ) {
	    tmp += data[now][j];
	  }
	  data[now].clear();
	  data[now - 1].push_back(tmp);
	}
	now--;
      }
      else {
	int tmp = 0;
	for(; s[i] != ']'; i++) {
	  tmp *= 10;
	  tmp += s[i] - '0';
	}
	i--;
	data[now].push_back((tmp + 1) / 2);
      }
    }

    cout << data[0][0] << endl;
  }
}