#590. 「Nowcoder多校 2019 Day4」tree

「Nowcoder多校 2019 Day4」tree

当前没有测试数据。

题目描述

You are given a tree A of n nodes.There are m queries .In each query,you are given a tree B of m nodes and you have to answer how many connected subgraphs of A is isomorphic to B.Because the answer may be too large,you only need to output it modulo 109+7 10^9+7 .

输入格式

The first line contains an integer n.

The next n-1 lines,each line contains two integers - the endpoints of an edge of A.

The next line, an integer t - the number of queries.

For each query:

The first line contains an integer m.

For each of the next m-1 lines, each line contains two integer - the endpoints of an edge of B.

输出格式

For each query, output a line containing one integer that stands for the answer.

样例

样例输入 1

4
1 2
1 3
1 4
1
2
1 2

样例输出 1

3

数据范围与提示

For all test datas, n≤2000,t≤10000, m≤12.