Hi Arjun
The issue with such a query is it would return two terminal BOM ID's, one at this connector and one at the other end. There is no way I know of in the query builder that would differentiate between the two.
This may be possible through a plugin query, though. I am not an expert on custom queries so I will let other comment on that
Thanks
Muhammad