Optimal multiple hypothesis testing and invariance applications