def prob(k)
  return 0.75 ** 8 if k == 0
  return 0.25 ** 8 if k == 8
  (1..8).inject(:*) / (1..k).inject(:*) / (1..8-k).inject(:*) * (0.25 ** k) * (0.75 ** (8 - k))
end

$prob = (0..8).map {|k| prob(k) }

def qualifiers(result)
  ret = []
  rest = [0, 1, 2, 3]

  qualify_by = proc do |criteria|
    g = rest.group_by {|i| criteria[i] }
    flag = false
    g.keys.sort.reverse.each do |k|
      if flag
        rest -= g[k]
      elsif ret.flatten.size + g[k].size <= 2
        ret << g[k]
        rest -= g[k]
      else
        flag = true
      end
    end
  end

  calc_points = proc do
    points = [0] * 4
    result.each_key do |i, j|
      s1, s2 = result[[i, j]]
      if s1 > s2
        points[i] += 3
      elsif s1 < s2
        points[j] += 3
      else
        points[i] += 1
        points[j] += 1
      end
    end
    points
  end

  calc_diffs = proc do
    diffs = [0] * 4
    result.each_key do |i, j|
      s1, s2 = result[[i, j]]
      diffs[i] += s1 - s2
      diffs[j] += s2 - s1
    end
    diffs
  end

  calc_goals = proc do
    goals = [0] * 4
    result.each_key do |i, j|
      s1, s2 = result[[i, j]]
      goals[i] += s1
      goals[j] += s2
    end
    goals
  end

  r = rest.size
  loop do
    result = Hash[result.keys.select {|i, j| rest.include?(i) && rest.include?(j) }.map {|i, j| [[i, j], result[[i, j]]] }]

    points = calc_points[]
    qualify_by[points]
    return ret if ret.flatten.size == 2

    diffs = calc_diffs[]
    qualify_by[diffs]
    return ret if ret.flatten.size == 2

    goals = calc_goals[]
    qualify_by[goals]
    return ret if ret.flatten.size == 2

    break if rest.size == r
    r = rest.size
  end

  ret << rest
  ret
end

n = gets.to_i
n.times do
  s = gets
  target = (0..3).find {|i| s[5 + 5 * i] == ?* }
  result = {}
  unplayed = []
  (0..2).each do |i|
    s = gets
    (i+1..3).each do |j|
      if s[6 + 5 * j] == ?_
        unplayed << [i, j]
      else
        result[[i, j]] = [s[6 + 5 * j].to_i, s[8 + 5 * j].to_i]
      end
    end
  end

  probs = []
  (0..8).to_a.repeated_permutation(4) do |scores|
    prob = scores.map {|k| $prob[k] }.inject(:*)
    result[unplayed[0]] = scores[0..1]
    result[unplayed[1]] = scores[2..3]
    a = qualifiers(result)
    if a[0].include?(target)
      if a[0].size == 1
        probs << prob
      else
        probs << prob * 2 / a[0].size
      end
    elsif a[1] && a[1].include?(target)
      probs << prob / a[1].size
    end
  end
  gets

  p probs.sort.inject(:+) || 0
end

