Seems like a lot of work to sort out all those categories. Have you looked at how essential and elegance handle custom category icons?
https://github.com/gjb2048/moodle-theme_essential/blob/master/settings.php#L1541-L1556
Create a setting for each category (with name, etc...). Once you have that then it's a matter calling it in the theme, checking isset() or empty() or something - and outputting or getting the parent.