select Name,UltimateMotherKIS__c,contract__r.Name FROM Account ^ ERROR at Row:1:Column:34 Didn't understand relationship 'contract__r' in the field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
There is a stranger relationship between Account and Contracts, It also took me for a while to understand. Please try to go for Inner query rather than using __r.Hopefully it will help.
Account has a one to many relationship with Contracts i.e. one account can have multiple contracts. Dot (.) operator is used when you want to get the parent field from child object. When you want to get the child records from parent object, you should use sub query (SOQL query) to get related childs of parent. In your case, to get related
Your SOQL query should be
select Id, Name, UltimateMotherKIS__c,(Select Id, Name from Contract) FROM Account
Contract is the child relationship name. From this SOQL query, you will get all the Accounts with its associated Contracts. This SOQL will return
List<Account> and each
Account record will have associated
List<Contract> within it. Post getting the records from SOQL, you should have the logic to pick suitable
Contract records from each