def bottom(arr)
  arr.sort[0, arr.size / 2 + 1].map{ |n| n / 2 + 1}.reduce(:+)
end

def top(arr)
  arr.sort[0, arr.size / 2 + 1].reduce(:+)
end

def aggregate(arr, isbottom)
  group = []
  arr.map { |v, g|
    ret = nil
    if g == 0
      group << v
    else
      unless group.empty?
        ret = [isbottom ? bottom(group << v) : top(group << v), g]
      else
        ret = [v, g]
      end
      group = []
    end
    ret
  }.compact
end

gets.to_i.times do
  str = gets.chomp.scan(/\[|\]|\d+/)
  gap = str.map.with_index{ |s, i| [s.to_i, i] if s != '[' && s != ']' }.compact
  stage = gap.transpose[0].zip(gap.transpose[1].each_cons(2).map{ |a, b| (b - a) / 2 - 1})
  stage = aggregate(stage, true)

  while stage.size > 1
    stage = stage.map{ |_, g|  g ? [_, g - 1] : [_, g] }
    stage = aggregate(stage, false)
  end
  p stage[0][0]
end