Given a preorder traversal of a BST, print the leaf nodes of the tree without building the tree.
The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains an integer N denoting the no of nodes of the BST. Then in the next line are N space separated values denoting the preorder traversal of the binary tree.
For each test case in a new line print the leaf nodes separated by space of the BST in sorted order.
890 325 290 530 965
3 2 4
290 530 965