#include <bits/stdc++.h>

using namespace std;

int pos;
string str;

int number() {

  // sentou digit
  int ret = 0;
  
  while(isdigit(str[pos])) {
    ret *= 10;
    ret += str[pos]-'0';
    pos ++;
  }
  // saigo not digit
  return ret;
}

vector<int> rec() {
  
  vector<int> ret;
  pos ++;
  
  if(isdigit(str[pos])) {
    ret.push_back(number()/2+1);
    return ret;
  }
  
  if(str[pos] == '[') {
    while(str[pos] == '[') {
      vector<int> r = rec();
      assert(str[pos] == ']');
      pos ++;
      assert(r.size() == 1);
      ret.push_back(r[0]);
    }
    
    sort(ret.begin(), ret.end());
    
    int sum = 0;
    for(int i=0; i<(int)ret.size()/2 + 1; i++) {
      sum += ret[i];
    }
    
    return vector<int>(1, sum);
  }
  pos ++;
  return ret;
}

int main() {
  
  int Tc; cin >> Tc;
  
  for(int Tcnt=1; Tcnt<=Tc; Tcnt++) {
    cin >> str;
    pos = -1;
    vector<int> ret = rec();
    assert(ret.size() == 1);
    cout << ret[0] << endl;
  }
  
  return 0;
}