Filter rules by terminals and select only reachable rules for each input.