#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;

const int MAX_N = 100;
int pos;
string s;

int dfs()
{
    vector<int> v;

    while (pos < s.size()) {
        int res = 0;
        if (s[pos] == '[') {
            pos++;
            v.PB(dfs());
        } else if (s[pos] == ']') {
            pos++;
            sort(ALL(v));
            REP(i, (v.size() + 1) / 2) res += v[i];
            return res;
        } else {
            while (isdigit(s[pos])) {
                res = res * 10 + (s[pos] - '0');
                pos++;
            }
            v.PB((res + 1) / 2);
        }
    }
}

int main()
{
    int n, ans[MAX_N] = {0};

    scanf("%d", &n);
    REP(i, n) {
        cin >> s;
        pos = 1;
        ans[i] = dfs();
    }

    REP(i, n) printf("%d\n", ans[i]);

    return 0;
}