As stated, make a custom context to figure out the extension.
[did-to-ext]
stuff here
Then make a Custom Destination that sends to it.
Then make an inbound route or three depending on what oyu need for a pattern match for the DIDs and make the destination the above custom destination.

