This can be quite complex, so lets just look at connecting up 1 site for the moment.
1. Create a trunk between site A and B and between B and A
2. In the dial plan on Site A, create a pattern match to grab all calls starting with 50 and 5 digits long, if found route them to the Site B trunk.
3. On Site B, use the pattern matching in the 'extension' field of the trunk to send the call to the specific extension.
For pattern matching look at the Wiki for a full explanation of how to do this http://wiki.pbxnsip.com/index.php/Inbound_Calls_on_Trunk
Repeat the process for all other sites.
NOTE: Inbound calls on trunk is dependant on how you set-up your PBX. If you use multiple domains you should use the tel:alias feature, if they are in one domain, then you can simply use the vanilla extension number to route the call directly to the extension.
You could also do this with DNS and not bother with a registered trunk.
There are many different ways to do this, it all depends on how you want configure the PBX