Converting a nested keyword list into a keyword map

I think I should probably be accomplishing what I need through the query in the first place rather than doing math on the whole database client side. The idea is to group c in b and b in a.

I want to show a distinct list of states, with a distinct list of cities with a list of all entries of c.

it should look like diagram