Solve task with double grouping.