#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
typedef long long ll;
using namespace std;

string str;
int idx;

int getn() {
    int res = 0;
    while (true) {
        char c = str[idx];
        if (isdigit(c)) {
            idx++;
            res *= 10;
            res += c-'0';
        } else {
            break;
        }
    }
    return res;
}

ll calc() {
    idx++;
    vector<ll> v;
    while (true) {
        char c = str[idx];
        if (c == ']') {
            idx++;
            break;
        }
        if (isdigit(c)) {
            int u = getn();
            v.push_back(u/2+1);
        } else {
            v.push_back(calc());
        }
    }
    sort(v.begin(), v.end());
    ll res = 0;
    //cout << v.size() << endl;
    for (int i = 0; i < v.size()/2+1; i++) {
        res += v[i];
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> str;
        idx = 0;
        cout << calc() << endl;
    }
}