### subroutines

def match?(ls, k, br)
  for i in (0...5)
    return false if ls[i][k] && ls[i][k] == br[i]
  end
  true
end

def vrec()
  k = 0
  while k < 5 && ! $vls[k].empty?
    k += 1
  end
  return 1 if k >= 5

  count = 0
  for i in (0...10)
    next if $used[i]

    if match?($hls, k, $brds[i])
      $used[i] = true
      $vls[k] = $brds[i]
      count += hrec()
      $vls[k] = []
      $used[i] = false
    end
    next if $brds[i] == $rbrds[i]
    
    if match?($hls, k, $rbrds[i])
      $used[i] = true
      $vls[k] = $rbrds[i]
      count += hrec()
      $vls[k] = []
      $used[i] = false
    end
  end
  count
end

def hrec()
  k = 0
  while k < 5 && ! $hls[k].empty?
    k += 1
  end
  return 1 if k >= 5

  count = 0
  for i in (0...10)
    next if $used[i]

    if match?($vls, k, $brds[i])
      $used[i] = true
      $hls[k] = $brds[i]
      count += vrec()
      $hls[k] = []
      $used[i] = false
    end
    next if $brds[i] == $rbrds[i]
    
    if match?($vls, k, $rbrds[i])
      $used[i] = true
      $hls[k] = $rbrds[i]
      count += vrec()
      $hls[k] = []
      $used[i] = false
    end
  end
  count
end

def kaibun?(br)
  br[0] == br[4] && br[1] == br[3]
end

### main

loop do
  line = gets.strip
  break if line == 'END'

  $brds = line.split.map{|str| str.split('').map{|b| b.to_i}}
  $rbrds = $brds.map{|br| br.reverse}
  #p $brds
  #p $rbrds
  
  $hls = 5.times.map{[]}
  $vls = 5.times.map{[]}
  $used = 10.times.map{false}

  $used[0] = true
  count = 0

  $hls[0] = $brds[0]
  count += vrec()
  $hls[0] = []

  $hls[1] = $brds[0]
  count += vrec()
  $hls[1] = []

  $hls[2] = $brds[0]
  count += vrec() / 2
  $hls[2] = []

  count /= 2 if kaibun?($brds[0])
  
  puts count
end