#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int solve(string line, int s, int t) {
    if (line[s] != '[') {
        return stoi(line.substr(s, t - s)) / 2 + 1;
    }
    vector<int> CS;
    while (s < t) {
        int ns = s + 1;
        int bs = 1;
        while (bs) {
            s++;
            if (line[s] == '[') bs++;
            if (line[s] == ']') bs--;
        }
        CS.push_back(solve(line, ns, s));
        s++;
    }
    sort(all(CS));
    int ans = 0;
    loop (CS.size() / 2 + 1, i) ans += CS[i];
    return ans;
}

int main()
{
    int n; cin >> n;
    while (n--) {
        string line; cin >> line;
        cout << solve(line, 1, line.size() - 1) << endl;
    }
    return 0;
}