#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;

int main(void) {
  int N; cin >> N;
  REP(i, 0, N) {
    string s; cin >> s;
    stack<int> stk;

    REP(i, 0, s.length()) {

      if(s[i] == '[') {
        stk.push(-1);
      } else if(s[i] == ']') {
        vector<int> v;
        while(1) {
          int d = stk.top();
          stk.pop();
          if(d == -1) break;
          v.push_back(d);
        }
        sort(v.begin(), v.end());
        int d = 0;
        REP(i, 0, (v.size() + 1) / 2) d += v[i];
        stk.push(d);
      } else {
        int d = 0;
        for(; '0' <= s[i] && s[i] <= '9'; i++) d = d * 10 + (s[i] - '0');
        i--;
        stk.push((d + 1) / 2);
      }
    }

    cout << stk.top() << endl;
  }
}