#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

const char *p;

int rec() {
  int res = 0;
  vector<int> v;

  ++p;
  if(*p == '[') {
    while(*p == '[') v.push_back(rec());
    sort(v.begin(), v.end());
    for(int i = 0; i < v.size()/2+1; i++) res += v[i];
  } else {
    char *e;
    res = strtol(p, &e, 10) / 2 + 1;
    p = e;
  }

  ++p;
  return res;
}

int main() {
  int n;
  string str;
  
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> str;
    p = str.c_str();
    cout << rec() << endl;
  }
  return 0;
}