#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cctype>
using namespace std;
 
typedef string::const_iterator iter;
 
int number(iter& p);
 
int expr(iter& p) {
    p++; // skip [
    int ans;
    if(isdigit(*p)) {
        int res = number(p);
        ans = res / 2 + 1;
    }
    else {
        vector<int> vec;
        while(*p == '[') {
            vec.push_back(expr(p));
        }
        sort(vec.begin(), vec.end());
        int res = 0;
        for(int i = 0; i < (int)vec.size() / 2 + 1; i++) {
            res += vec[i];
        }
        ans = res;
    }
    p++; // skip ]
    return ans;
}
 
int number(iter& p) {
    int res = 0;
    while(isdigit(*p)) {
        res *= 10;
        res += *p - '0';
        p++;
    }
    return res;
}
 
int main() {
    int n; cin >> n;
    while(n-- ){
        string s; cin >> s;
        iter it = s.begin();
        int res = expr(it);
        cout << res << endl;
    }
}
 