Need help on interacting with multiple instances of a BP

I guess to specify how would I detect the specific component(one of the white cubes) with a linetrace and then depending on the component, rotate either clockwise or counter clockwise?