Fixes: U4-3051 GetAncestorOrSelfDocuments gets stuck in infinite loop

Minor code change to `uQuery` extension methods to check if the `Document`/`Media` has reached the root node.