building the singleton tree and ordering into priority queue