SELECT ?a ?b WHERE { ?s ?p ?o . BIND( STR( ?o ) AS ?a ) BIND( STR( ?s ) AS ?c ) } GROUP BY ?a ?b