A school has a total of $3*n$ students, divided evenly into $A$ group, $B$ group or $C$ group, with $n$ in each group. Everyone has an ability value $v_i$, the tacit value between two students is $f(i,j)=(v_i+v_j)*(v_i \oplus v_j) \% M$, where $\oplus$ means bitwise exclusive OR operation. As the competition coach of this school, you need to select exactly $m$ teams to participate in the $CCPC$ competition in the second half of the year.
Specifically, Each team contains exactly three students, and the three students are from different groups.
Let the team members from the $A,B,C$ group be $a,b,c$, then the tacit value of this team is $f(a,b)+f(a,c)$.
Please find out the maximum sum of the tacit values of the $m$ teams.