def choose(m) self.factorial / (m.factorial * (self - m).factorial) end def fact (n) if n < 2 return 1 end (2..n).inject(1) { |f, n| f * n } end mod = 10**9 + 7 t = gets.to_i while t > 0 s = gets.chomp s = s.gsub("j","") s = s.gsub("J","") s = s.gsub("u","") s = s.gsub("U","") s = s.gsub("w","") s = s.gsub("W","") n = s.length m = n count = [] i = 0 while i < n count << s.count(s[i]) i = i + s.count(s[i]) end n = count.length deno = 1 (0..n-1).each{ |i| deno = deno * fact(count[i]) } if(m != 0 ) print "#{(fact(18)/567334383}\n" else puts "0" end t= t - 1 end