Measurements of the branching fractions for B(s)→D(s) pi pi pi and Lambda_b^+ → Lambda_c^+ pi pi pi