#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

void down_kaisou(int max_kaisou, queue<pair<int, char> > &que) {
    queue<pair<int, char> > temp;
    bool down;
    while (!que.empty()) {
        pair<int, char> inque = que.front();
        //cout << "HERE : " <<  inque.first << " " << inque.second << endl;
        if (inque.first != -max_kaisou) {
            //cout << "HERE3 : " <<  inque.first << " " << inque.second << endl;
            temp.push(inque);
            que.pop();
        } else {
            vector<int> v;
            int num = 0;
            down = false;
            while (!down) {
                pair<int, char> inque2 = que.front();
                if (inque2.first == -max_kaisou + 1) {
                    int p_que = 0;
                    sort(v.begin(), v.end());
                    for (int k = 0; k < num / 2 + 1; k++) {
                        p_que += v[k]; 
                    }
                    // pushテ」ツ?療」ツ?淌」ツ??
                    temp.push(make_pair(p_que, '0'));
                    temp.push(make_pair(-max_kaisou, ']'));
                    down = true;
                    //cout << "PQ = " << p_que << endl;
                    break;
                }
                if (inque2.second == '0') {
                    v.push_back(inque2.first);
                    num++;
                }
                //cout << "HERE2 : " <<  inque2.first << " " << inque2.second << endl;
                que.pop();
            }
        }
    }
    while (!que.empty()) {
        pair<int, char> inque2 = que.front();
        //cout << "HERE2 : " <<  inque2.first << " " << inque2.second << endl;
        que.pop(); 
    }
    que = temp;
    return;
}

int main(void) {
    int n;
    int max_kaisou;
    cin >> n;
    for (int loop = 0; loop < n; loop++) {
        string s;
        cin >> s;
        max_kaisou = 0;
        queue<pair<int, char> > que;
        int kaisou = 0;
        int num = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s[i] == '[') {
                kaisou++;
                if (max_kaisou < kaisou) {
                    max_kaisou = kaisou; 
                }
                que.push(make_pair(-kaisou, '[')); 
            } else if (s[i] == ']') {
                num /= 10;
                if (num != 0) {
                    num = num / 2 + 1;
                    que.push(make_pair(num, '0'));
                    //cout << "NUM = " << num << endl;
                }
                num = 0;
                que.push(make_pair(-kaisou, ']')); 
                kaisou--;
            } else {
                num += s[i] - '0';    
                num *= 10;
            }
        }
        while (max_kaisou > 1) {
            //cout << "KAISOU = " << max_kaisou << endl;
            down_kaisou(max_kaisou, que);
            max_kaisou--;
        }
        while (1) {
            pair<int, char> inque = que.front();
            //cout << "OUT : " <<  inque.first << " " << inque.second << endl;
            if (inque.second == '0') {
                cout << que.front().first << endl;
                break;
            }
            que.pop();
        }
        /*
           while (!que.empty()) {
           cout << que.front().first << " " << que.front().second << endl; 
           que.pop();
           }
           cout << endl;
         */
    }
    return 0;
}

Measured memory_bytes: 3260