#include<iostream>
#include<string>
#include<cctype>
#include<vector>
#include<algorithm>
using namespace std;
string s;
int now;
int rec(){
  if(isdigit(s[now])){
    int res = 0;
    while(now < s.size() && isdigit(s[now])) res = res * 10 + s[now++] - '0';
    return (res + 1) / 2;
  }else{
    vector<int> dat; int res = 0;
    while(s[now] == '[') now++ , dat.push_back(rec()) , now++;
    sort(dat.begin(),dat.end());
    for(int i = 0 ; i < ( dat.size() + 1 ) / 2 ; i++ ) res += dat[i];
    return res;
  }
}
int main(){
  int q;
  cin >> q;
  while(q--){
    now = 0;
    cin >> s;
    cout << rec() << endl;
  }
}