public static <E> void reversedBFSWithLine(KAryTreeNode<E> root) {
		if(root == null) {
			return;
		}

		ArrayList<Integer> lineNodeCount = new ArrayList<Integer>();
		Queue<KAryTreeNode<E>> queue = new LinkedList<KAryTreeNode<E>>();
		Stack<KAryTreeNode<E>> stack = new Stack<KAryTreeNode<E>>();
		queue.add(root);
		lineNodeCount.add(1);
		lineNodeCount.add(0);
		int nextLine = 1;
		int currLineNode = 0;

		while(!queue.isEmpty()) {
			KAryTreeNode<E> node = queue.poll();
			stack.push(node);
			currLineNode++;

			for(int i=node.children.length-1;i>=0;i--) {
				if(node.children[i] != null) {
					queue.offer(node.children[i]);
					lineNodeCount.set(nextLine, lineNodeCount.get(nextLine)+1);
				}
			}

			if(currLineNode == lineNodeCount.get(nextLine-1)) {
				nextLine++;
				currLineNode = 0;
				lineNodeCount.add(0);
			}
		}

		int height = lineNodeCount.size()-3; // because there will be two 0s at the tail of line node count list
		while(!stack.isEmpty()) {
			KAryTreeNode<E> node = stack.pop();
			System.out.print(node.value + " ");
			lineNodeCount.set(height, lineNodeCount.get(height)-1);
			if(lineNodeCount.get(height)==0) {
				System.out.println();
				height--;
			}
		}
	}