what is the {statement is subject of} for {Iran} has {shares border with} as {Afghanistan} ?
Which country has Iran and Afghanistan on its border?
What country shares a border with Iran and Afghanistan?
SELECT ?o WHERE { ?g property:statement_is_subject_of ?o . ?g property:shares_border_with resource:Afghanistan . resource:Iran property:shares_border_with ?g }
select distinct ?value  where {
?statement <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> <http://wikidata.dbpedia.org/resource/Q794> .
?statement <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate> <http://www.wikidata.org/entity/P47> .
?statement <http://www.w3.org/1999/02/22-rdf-syntax-ns#object> <http://wikidata.dbpedia.org/resource/Q889> .
?statement <http://www.wikidata.org/entity/P805> ?value. 
} 

SELECT ?value WHERE { wd:Q794 p:P47 ?s . ?s ps:P47 wd:Q889 . ?s pq:P805 ?value}