### subroutines

def parse_num(str)
  num = 0
  while str[$pos] >= '0' && str[$pos] <= '9'
    num = num * 10 + str[$pos].to_i
    $pos += 1
  end
  num
end

def parse(str)
  return 'N/A' if str[$pos] != '['
  $pos += 1

  if str[$pos] >= '0' && str[$pos] <= '9'
    num = parse_num(str)
    $pos += 1
    return (num + 1) / 2
  end

  ds = []
  nds = 0
  while str[$pos] == '['
    ds << parse(str)
    nds += 1
  end
  $pos += 1
  
  ds.sort[0..(nds / 2)].inject(:+)
end

### main

n = gets.to_i

n.times do
  str = gets.strip
  $pos = 0
  
  puts parse(str)
end