require 'set'


Primes = [ 2,  3,  5,  7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 
          43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101]
States = [
    , , , , , ,
    , , , , , ,
    , , , , , , ,
    , , , , ,
    , , , , , ,
    , , , , ,
    , , , , ,
    , , , , , ,
    , , , 
]

def print_answer(states)
  
  goedel = lambda {|str| str.chars.map {|c| Primes[c.ord - 65]}.reduce(:*)}
  pairs = Hash.new {|h,k| h[k] = Array.new}
  map = states.uniq.map {|state| [state, goedel[state.upcase.delete()]]}
  map.combination(2) {|(s1,g1), (s2,g2)| pairs[g1 * g2] << [s1, s2]}

  
  result = []
  pairs.values.select {|val| val.length > 1}.each do |list_of_pairs|
    list_of_pairs.combination(2) do |pair1, pair2|
      if Set[*pair1, *pair2].length == 4
        result << [pair1, pair2]
      end
    end
  end

  
  result.each_with_index do |(pair1, pair2), i| 
    puts  % [i+1, pair1.join(', '), pair2.join(', ')]
  end
end

puts 
print_answer(States)
puts 
puts 
print_answer(States + [, , , , ])