Associated Course(s):
Interview Preparation
Geeks Classes DSA

Given **N**, number of edges for a graph. The task is to do Breadth First Search of this graph.

**Input:**

First line of input contains number of testcases T. For each testcase, first line of input contains N, for which 2*N numbers (N pairs as X Y) are given in the next line which represents an edge from X to Y.

**Output:**

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

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

**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 1 and prints the nodes in BFS order.

**Constraints:**

1 <= T <= 100

1 <= N <= 100

**Example:
Input:**

1

4

1 2 1 3 1 4 3 5

**Output:**

1 2 3 4 5 // BFS from node 1

**Explanation:
Testcase 1:** There is one test cases. First line of each test case represent an integer N denoting no of edges and then in the next line N pairs of values

lakshmi_pandey | 72 |

abbatta7 | 68 |

Ashish Kumar Vaishy | 62 |

aman19 | 58 |

Kumar Gaurav Singh | 58 |

saumitra13325 | 612 |

ashujack | 551 |

lakshmi_pandey | 544 |

aman19 | 538 |

piyushmittal25 | 514 |

blackshadows | 5249 |

akhayrutdinov | 5111 |

Ibrahim Nash | 5087 |

Quandray | 4354 |

sanjay05 | 3668 |

Login to report an issue on this page.