def spin(a)
	[a[0]] + a[5..6] + a[1..4] + [a[7]]
end

def roll(a)
	a[1..3] + [a[0]] + a[5..7] + [a[4]]
end

while gets
	hash = {}
	a = $_.chomp.split.map{|x| hash[x] ||= hash.size}.sort
	count = 0
	a[1..-1].permutation{|x|
		x.unshift 0
		stack = [x]	
		reached = {}
		ok = true

		while y = stack.pop
			next if reached[y]
			reached[y] = 0
			if hash[y]
				ok = false
				break
			end
			stack << spin(y)
			stack << roll(y)
		end

		hash[x] = 0
		count += 1 if ok
	}
	p count
end