#include <stdio.h>
#include <stdlib.h>

char s[10001];
int n,count=0,i;

int dfs();
int cmp(const void *p1,const void *p2){
  return *(int*)p1-*(int*)p2;
}

int main(void){
  int a,ans=0;
  scanf("%d",&n);
  scanf("%c",&s[0]);
  for(a=0;a<n;a++){
    i=0;
    count=0;
    while(1){
      scanf("%c",&s[count]);
      if(s[count]=='\n')break;
      count++;
    }
    i=0;
    ans = dfs();
    printf("ans=%d\n",ans);
  }
  return 0;
}

int dfs(){
  int ca=0,j,ans=0;
  int ab[4000];
  i++;
  if(s[i]>='0'&&s[i]<='9'){
    int x=0;
    while(s[i]>='0'&&s[i]<='9'){
      x = x*10+s[i]-'0';
      i++;
    }
    printf("%d ",x);
    i++;
    return (x/2)+1;
  }

  else  while(s[i]=='['){
      ab[ca]=dfs();
      ca++;
    }
  qsort(ab,ca,sizeof(int),cmp);
  for(j=0;j<(ca/2)+1;j++)ans+=ab[j];
  i++;
  return ans;
}

