#include <iostream>
#include <cctype>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int block(string &s, int &i);
int number(string &s, int &i);

int block(string &s, int &i)
{
  i++;
  if(s[i] == '['){
    vector<int> v;
    while(s[i] == '['){
      v.push_back(block(s, i));
      i++;
    }
    sort(v.begin(), v.end());
    return accumulate(v.begin(), v.begin() + v.size()/2+1, 0);
  }else{
    return number(s, i);
  }
}

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

int main()
{
  int n;
  cin >> n;
  for(int j = 0; j < n; j++){
    string s;
    cin >> s;
    int i = 0;
    cout << block(s, i) << endl;
  }
}