Given **N** and **E**, the number of nodes and edges in a directed graph. The task is to do Breadth First Search of this graph.

**Input:**

The first line of the input contains an integer **'T'** denoting the number of test cases. Then **'T'** test cases follow. Each test case consists of two lines. Description of testcases is as follows: The First line of each test case contains two integers **'N' and 'E' ** which denotes the no of vertices and no of edges respectively. The Second line of each test case contains **'E' ** space separated pairs **u** and **v** denoting that there is a edge from **u** to **v** .

**Output:**

For each testcase, print the BFS of the graph starting from 0.

**Note:** The expected output button always produces BFS starting from node 0.

**User Task:**

Since, this is a functional problem, your task is to complete the function **bfs**() which do BFS of the given graph starting from node 0 and prints the nodes in BFS order.

**Constraints:**

1 <= T <= 100

1 <= N <= 100

**Example:
Input:**

2

5 4

0 1 0 2 0 3 2 4

3 2

0 1 0 2

**Output:**

0 1 2 3 4 // BFS from node 0

0 1 2

**Explanation:
Testcase 1:**

0 is connected to 1 , 2 , 3

2 is connected to 4

so starting from 0 , bfs will be 0 1 2 3 4.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

saiujwal13083 | 489 |

sudeep235poojary | 302 |

VithalNakod | 272 |

AshutoshPal1 | 254 |

go__karuna | 253 |

Soseph_Jtalin | 792 |

AshutoshPal1 | 722 |

architjindal__ | 648 |

go__karuna | 577 |

ArbazGrewal | 527 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4931 |

Quandray | 4598 |

Login to report an issue on this page.