select distinct ?x ?p1 ?p2 ?p3 where { ?x . ?y . ?x ?p1 ?y. ?z ?y. ?z . ?z ?p2 ?w. ?w ?p3 . }