Implementation and test cases for SelectPrefix