2 answers

Hi Sreenivas,May I suggest you please check with below links on how to query the relationship objects in Salesforce. Please tweak it as per your objects so that it can help you out.
- https://webkul.com/blog/relationship-query-salesforce/
- http://www.sfdcpoint.com/salesforce/relationship-query-apex-salesforce/
Hope this helps.
Kindly mark this as solved if the reply was helpful.Thanks,Nagendra