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

int parse(string &S, int l, int r){
  int ret = 0;
  if(S[l] != '['){
    for(int i = l; i < r; ++i){
      ret *= 10;
      ret += S[i] - '0';
    }
    return (ret+1)/2;
  }
  vector<int> V;
  int t = 0;
  for(int i = l; i < r; ++i){
    if(S[i] == '[') ++t;
    else if(S[i] == ']') --t;
    if(!t){
      V.push_back(parse(S,l+1,i));
      l = i+1;
    }
  }
  sort(V.begin(),V.end());
  for(int i = 0; i < ((int)V.size()+1)/2; ++i)
    ret += V[i];
  return ret;
}

int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i){
    string S;
    cin >> S;
    cout << parse(S,0,(int)S.size()) << endl;
  }
  return 0;
}