Ali hamed little brother tomorrow birthday Hamed want brother earn gift give hard programming problem tell successfully solve hell brand new laptop Ali talented programmer like Hamed usually do not cheat time exception its brand new laptop so decide secretly seek help please solve problem Ali an nvertex weight rooted tree give Vertex number 1 root tree we define duv sum edge weight short path vertex u v specifically define duu0 also let define Sv vertex v set contain vertex u d1ud1vdvu Function fuv define follow formulaThe goal calculate fuv q give pair vertex as answer large print modulo 1097