Teacher Mai has $m+1$ trees, $T_0,T_1,\cdots,T_m$. $T_0$ consists one vertex numbered $0$.
He generated the $T_i$ in this way. Get a copy of $T_{a_i}$ and $T_{b_i}$. Add an edge with length $l_i$ between vertex numbered $c_i$ in $T'_{a_i}$ and $d_i$ in $T'_{b_i}$. Relabel the vertices in the new tree. Let $k$ be the number of vertices in $T'_{a_i}$. He keeps labels of vertices in $T'_{a_i}$ the same, and adds $k$ to labels of vertices in $T'_{b_i}$.
If there is a tree $T$ with $n$ vertices $v_0,v_1,v_2,\cdots,v_{n-1}$, $F(T)=\sum_{i=0}^{n-1} \sum_{j=i+1}^{n-1} d(v_i,v_j)$($d(v_i,v_j)$ means the distance between the $v_i$ and $v_j$).
For every $i(1\leq i\leq m)$, he wants to know $F(T_i)$.