### subroutines

def point(gls, ti, ops)
  win = glp = glm = 0

  for op in ops
    gli = gls[ti][op]
    glo = gls[op][ti]

    if gli > glo
      win += 3
    elsif gli == glo
      win += 1
    end

    glp += gli
    glm += glo
  end

  win * 10000 + (glp - glm + 32) * 100 + glp
end

def check_order(gls, tis)
  return [tis] if tis.length <= 1

  phash = {}

  for i in (0...tis.length)
    ti = tis[i]
    ops = tis.clone
    ops.delete_at(i)
    pt = point(gls, ti, ops)
    #p [tis[i], pt]

    phash[pt] = [] if phash[pt].nil?
    phash[pt] << ti
  end

  mtis = phash.keys.sort{|a, b| b <=> a}.map{|pt| [phash[pt]]}.inject(:+)
  return mtis if mtis.length == 1

  mtis.map{|tis0| check_order(gls, tis0)}.inject(:+)
end

### main

fact = [1]
(1..8).each{|n| fact[n] = n * fact[n - 1]}
#p fact

prbs = []
for k in (0..8)
  prbs[k] =
    Rational(fact[8], fact[k] * fact[8 - k]) *
    (Rational(1, 4) ** k) *
    (Rational(3, 4) ** (8 - k))
end
#p prbs
#p prbs.inject(:+)

n = gets.to_i

n.times do
  lines = []
  5.times do
    str = gets.strip
    line = []
    (0..4).each{|i| line[i] = str[5 * i, 4]}
    lines << line
  end
  #p lines

  teams = []
  thash = {}
  oid = nil

  for i in (0...4)
    team = lines[0][i + 1]
    teams << team
    thash[team] = i
    oid = i if team =~ /^\*/
  end
  #p teams
  #p thash
  #p oid

  gls = 4.times.map{4.times.map{nil}}
  ops = []

  for i in (0...4)
    for j in ((i + 1)...4)
      gl = lines[i + 1][j + 1]
      #p [i, j, wl]
      if gl[1] != '_'
        gls[i][j] = gl[1].to_i
        gls[j][i] = gl[3].to_i
      else
        ops[i] = j
        ops[j] = i
      end
    end
  end
  #p gls
  #p ops

  sump = 0

  for cnt in (0...9 ** 4)
    cnt0 = cnt
    scs = []
    for i in (0...4)
      scs << cnt0 % 9
      cnt0 /= 9
    end
    #p scs

    for i in (0...4)
      gls[i][ops[i]] = scs[i]
    end
    #p gls

    mtis = check_order(gls, (0...4).to_a)

    r0 = r1 = 0
    for tis in mtis
      r0 = r1
      r1 = r0 + tis.length

      if tis.include?(oid)
        break if r0 >= 2

        pr = scs.map{|sc| prbs[sc]}.inject(:*)
        if r1 <= 2
          sump += pr
        else
          sump += pr * Rational(2 - r0, r1 - r0)
        end
      end
    end
  end

  puts "%.7f" % sump.to_f
end