An optimal design for hierarchical generalized group testing