This depends on how you want to display them.
The easiest would be a Report using Accounts with Contacts report type. With that you can just set the Grouping to be by Lookup (Master Detail) field on Accounts. This will group all the Contacts related to Accounts related to the X objects.
If you want them to appear as a Related List on the Page Layout you will need to have a direct relationship from the Contacts to the X Object. It does not need to be Master Detail. This can be set via automation in numerous ways.