If you need to rebuild the hierarchy, then you need a self recursive script. WARNING: This may get slow and do NOT get it wrong or it'll run forever. I've done it a few times to trace back up the list looking for where the user gets it - its never pretty.
Also, you'll need to search the entire list in case they get it from multiple places.