I tried to generate formulas for the same using chatgpt, but the results were not apt.
Here's another solution:
={"Village","Class","Team";
ARRAYFORMULA(
QUERY(
SPLIT(
TOCOL(
TOCOL(TOCOL(A2:A,3)&"ζ"&B1:C1)&"ζ"&
MAP(TOCOL(B2:C,3),LAMBDA(n,SEQUENCE(1,n)))),
"ζ"),
"where Col3 is not null"))}
This formula is a variation of the standard unpivoting formula.