Did {Gibraltar} {territory claimed by} {United Kingdom} and {Spain} ?
Was territory in both the United Kingdom and Spain claimed by Guam?
Did Gibraltar claim territory in both the United Kingdom and Spain?
ASK WHERE { resource:Gibraltar property:territory_claimed_by resource:United_Kingdom . resource:Gibraltar property:territory_claimed_by resource:Spain }
 ASK { ?statement1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> <http://wikidata.dbpedia.org/resource/Q1410> . ?statement1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate> <http://www.wikidata.org/entity/P1336> . ?statement1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#object> <http://wikidata.dbpedia.org/resource/Q145>. ?statement2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> <http://wikidata.dbpedia.org/resource/Q1410> . ?statement2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate> <http://www.wikidata.org/entity/P1336> . ?statement2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#object> <http://wikidata.dbpedia.org/resource/Q29>. } 
ASK WHERE { wd:Q1410 wdt:P1336 wd:Q145 . wd:Q1410 wdt:P1336 wd:Q29 }