gets li = gets.chomp abort unless li=~/^[A-Za-z]+$/ abort if li=~/H/ if li=~/^[^HQ]*Q[^HQ]*$/ puts li else p -1 end