

The graph may contain cycles.
The first line of each test case contains two space-separated integers 'N' and 'E', the number of nodes and edges in the graph respectively.
The following 'E' lines contain two space-separated integers 'U' and 'V', denoting an undirected edge between the nodes 'U' and 'V'.
The next line contains an integer, 'M', denoting the number of queries.
Then 'M' lines follow:
Each line consists of two integers 'S' and 'T', where 'S' denotes the source node, and 'T' denotes the connectivity distance to be processed.
For each query, print a single line containing a single integer denoting the count of nodes as asked in the problem statement.
The output of each test case will be printed in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= N <= 3 * 10 ^ 3
1 <= E <= 10 ^ 4
1 <= U, V <= N
1 <= M <= 100
1 <= S <= N
1 <= T <= 2500
Time Limit: 1 sec.
It’s clearly visible that we need to traverse the graph optimally in order to get our answer.We will use Breadth First Search to achieve this. Let’s understand how to do this.