You can't query OSM directly for this information. Of course OSM contains such information, mainly through boundary relations and admin_levels. But the exact hierarchy between different elements has to be calculated first.
Geocoders for OSM can be used to obtain these information. The currently most popular one is Nominatim. You can install your own Nominatim instace by either importing the whole planet or an country or area extract. Then you can try to obtain these information via the database created by Nominatim.