Standard and custom objects and standard and custom fields are queried in SOQL in exactly the same way. The main difference is in the API names of the objects, fields and relationships.
To query the Territory__c instances you would do:
SELECT Id, Name, Territory_Ex_ID__c FROM Territory__c WHERE ...
Standard objects and fields do not have the suffix "__c" and don't use the suffix "__r" for relationships. For example: the standard Contact object has a standard lookup field "AccountId" that references an Account object, and the equivalent relationship field "Account".
On the other hand, custom objects and fields always have the suffix "__c" in the API name, and relationships end with "__r". For example: a custom Example__c object could have a custom lookup field "Account__c" that references an Account object, and the equivalent relationship field "Account__r".
You will find some useful information in the Salesforce documentation for objects and fields.