Three Musketeers !

0

0 votes
Hard
Problem

Athos , Aramis and Porthos decided to meet to counsel their young friend D'Artagnan . But the three musketeers are unable to decide a meeting place as none of them wants to walk more distance than the other . The city in which they live is in shape of a tree where the streets of the city can be imagined as nodes of the tree and roads connecting two streets as edges . They are relying on you to help them find a meeting place . You have to find number of different streets in which they can meet . ( Consider all roads of equal length )

Input:
First line contains integer T denoting number of testcases .

For each testcase :

First line contains integer N denoting number of streets in the city .

Next N-1 lines contain two integers X and Y , which states that there is a road connecting streets X and Y .

Next line conatins integer Q denoting number of queries .

Each Query conatins three integers A , B , C which denotes the streets in which the three musketeers are in .

Output:
For each query , find the number of streets in which the three musketeers can meet .

Constraints:
1<=T<=10

1<=N<=10^5

1<=Q<=10^5

1<=A , B , C<=N

Setter: _Mr_Fab

Time Limit: 3
Memory Limit: 256
Source Limit:
Editor Image

?