#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<ll, ll>;
using namespace std;

template<class t> void vin(vector<t>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int number(string& s, int& i) {
    int n = 0;
    while (s[i] != ']') {
        n *= 10;
        n += s[i] - '0';
        i++;
    }
    return n;
}

int solve(string& s, int& i) {
    if (s[i] != '[') return -1;
    if (s[++i] != '[') return number(s, i)/2 + 1;
    vector<int> a;
    while (s[i] == '[') {
        a.push_back(solve(s, i));
        i++;
    }
    sort(a.begin(), a.end());
    int ans = 0;
    rep(j, a.size()/2+1) ans += a[j];
    return ans;
}

int main() {
    int n;
    cin >> n;
    rep(i, n) {
        string s;
        cin >> s;
        int idx=0;
        cout << solve(s, idx) << endl;
    }
    return 0;
}

