#include <algorithm>
#include <iostream>

#include <cmath>
#include <iomanip>
#include <vector>
#include <string>

using namespace std;
#define int ll
#define ll long long

#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define REP(i, n) for (int i = 0; i < (int)n; ++i)

string s;
int now=0;

int solve(){
  now++;
  if(isdigit(s[now])){
    int t=0;
    while(isdigit(s[now])){
      t = t*10+(s[now]-'0');
      now++;
    }
    return (t+1)/2;
  }
  vector<int>tmp;
  while(now<s.size()&&s[now]!=']'){
    if(s[now]=='[')tmp.push_back(solve());
    now++;
  }
  //now++;
  sort(ALL(tmp));
  //cout<<"//"<<endl;
  //REP(i,tmp.size())cout<<tmp[i]<<endl;
  //cout<<"end"<<endl;
  int ret = 0;
  REP(i,(tmp.size()+1)/2)ret += tmp[i];
  return ret;
}

signed main() {
  int N;
  cin>>N;
  vector<int> ans;
  REP(i,N){
    cin>>s;
    now = 0;
    ans.push_back(solve());
  }
  for(auto e:ans)cout<<e<<endl;
  return 0;
}

