Given root of binary search tree and K as input, find K-th smallest element in BST. Your task is to return the K-th smallest element in BST from the function **k_smallest_element().**

**Note:** The Time Complexity will be O(h) where h is the height of the Tree.

**Input:**

The first line of input will contain the number of test cases T. Then T test cases follow. First line of every test case will be n, denoting the number of nodes in the BST. Second line of every test case will be n spaced integers denoting the Integer value of Nodes in BST. Third line of every test case will be k, denoting kth the smallest number.

**Output:**

For each test case, output will be the kth smallest element of BST.

**Constraints:**

1<=T<=100

1<=N<=100

1<=K<=N

**Example(To be used only for expected output):
Input:**

1

5

20 8 4 22 12

3

12

Author: saksham seth

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.

hardikJain5 | 234 |

CodeBuddy | 196 |

bhatabhi554 | 172 |

Akkki111 | 169 |

clone | 166 |

KshatriyaYash | 1932 |

nikhil_sojan | 1374 |

lonecoder | 1236 |

SumitSingh27 | 1127 |

mazumderrohit8 | 1108 |

blackshadows | 5327 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4587 |

Quandray | 4444 |

Login to report an issue on this page.