#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct Lex {
  Lex(){}
  void load(string s){ S = s; }
  int solve(){
    char *p = (char*)S.c_str();
    return eval(&p);
  };
  int eval(char** p){
    if (isdigit(**p)){
      int r = 0;
      while (isdigit(**p)){
        r = r * 10 + **p - '0';
        (*p)++;
      }
      return (r + 1) / 2;
    }
    vector<int> costs;
    while (**p == '['){
      consume(p, '[');
      costs.push_back(eval(p));
      consume(p, ']');
    }
    sort(costs.begin(), costs.end());
    int n = (costs.size() + 1) / 2;
    int r = 0;
    for (int i = 0; i < n; i++) r += costs[i];
    return r;
  }
  void consume(char** p, char expected){
    assert(**p == expected);
    (*p)++;
  }
  string S;
};

int main()
{
  int n;
  cin >> n;
  for (int i = 0; i < n; i++){
    string s;
    cin >> s;
    Lex lex;
    lex.load(s);
    cout << lex.solve() << endl;
  }

  return 0;
}