What is {country} of {Lviv} that is {end time} is {1348-0-0} ?
In 1348, where did Lviv live?
What country did Lviv live in in 1348-0-0?
SELECT ?t WHERE { FILTER ( CONTAINS ( YEAR ( ?m ) , '1348' ) ) . ?h property:end_time ?m . ?h property:country ?t . resource:Lviv property:country ?h }
select distinct ?obj  where {
?statement <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> <http://wikidata.dbpedia.org/resource/Q36036> .
?statement <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate> <http://www.wikidata.org/entity/P17> .
?statement <http://www.w3.org/1999/02/22-rdf-syntax-ns#object> ?obj .
?statement <http://www.wikidata.org/entity/P582> <1348-0-0>
} 

SELECT ?obj WHERE { wd:Q36036 p:P17 ?s . ?s ps:P17 ?obj . ?s pq:P582 ?x filter(contains(YEAR(?x),'1348')) }