#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>

using namespace std;
string s;
int pos;

int calc(vector<int> &v){
  sort(v.begin(),v.end());
  int res=0,len=v.size();
  for(int i=0;i<(len-len/2);i++){
    res+=v[i];
  }
  return res;
}

int solve();
int getNum();

int getNum(){
  int res=0;
  while(1){
    if('0'<=s[pos]&&s[pos]<='9'){
      res*=10;
      res+=(s[pos]-'0');
      pos++;
    }else break;
  }
  return res-res/2;
}

int solve(){
  vector<int> v;

  pos++;
  if(s[pos]!='['){
    int res=getNum();
    pos++;
    return res;
  }

  while(1){
    v.push_back(solve());
    if(s[pos]==']')break;
  }

  if(s[pos]==']')pos++;
  else assert(0);

  if(v.size()==1)return v[0];
  else return calc(v);
}

int main(){
  int Tc;
  cin>>Tc;
  while(Tc--){
    cin>>s;
    pos=0;
    cout<<solve()<<endl;
  }
  return 0;
}