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

long long int kansu( long long int x ) {
  vector< long long int > list;
  long long int k = 0;
  while( true ) {
    if ( input[x] == '[' ) {
      list.push_back( kansu(x+1) );
      long long int f = 0;
      while( true ) {
	if ( input[x] == '[' ) f++;
	if ( input[x] == ']' ) {
	  f--;
	  if ( f == 0 ) break;
	}
	x++;
      }
      x++;
      if ( x == input.size() ) break;
    }else if ( input[x] == ']' ) {
      if ( k > 0 ) list.push_back( k / 2 + 1 );
      break;
    }else {
      k = k * 10 + input[x] - '0';
      x++;
    }
  }
  sort( list.begin(), list.end() );
  long long int ans = 0;
  for ( long long int i = 0; i < list.size() / 2 + 1; i++ ) {
    ans += list[i];
  }
  return ans;
}

int main () {

  long long int n;

  cin >> n;

  for ( long long int i = 0; i < n; i++ ) {
    cin >> input;
    cout << kansu( 0 ) << endl;
  }

  return 0;

}