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

int now;
string s;

int calc(){
    vector<int> v;
    int ret = 0;
    while(s[now]!=']'){
        if(s[now]=='['){
            now++;
            v.push_back(calc());
        }
        else{
            int x=0;
            while(s[now]>='0' && s[now]<='9'){
                x=x*10+s[now]-'0';
                now++;
            }
            ret = x/2 + x%2;
        }
    }
    now++;
    if(ret==0){
        sort(v.begin(),v.end());
        int vs=v.size();
        for(int i=0;i<(vs/2 + vs%2);i++){
            ret+=v[i];
        }
    }
    //cout << ret << endl;
    return ret;
}

int main(void){
    int n,ret;
    cin >> n;
    while(n--){
        cin >> s;
        now=1;
        ret=calc();
        cout << ret << endl;
    }
}

