query-bfdc7be87191fb41dd2a4d51cfbf1560

rq turtle/ttl

What is Lipovica's current country? has belonged to several countries during its history. (Q6556803)Lipovicë country? currentMy query: What is Lipovica's . endtime is to do a normal wdt:P131*/wdt:P17 but filter out all levels that have a An ideaThe query below unfortunately times out, can you help me fix it?

Use at

PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
SELECT ?country WHERE {
 wd:Q6556803 wdt:P131* ?area.
 ?area wdt:P17 ?country.
 FILTER NOT EXISTS {
  wd:Q6556803 p:P131/(ps:P131/p:P131)* ?statement.
  ?statement ps:P131 ?area.
  wd:Q6556803 p:P131/(ps:P131/p:P131)* ?intermediateStatement.
  ?intermediateStatement (ps:P131/p:P131)* ?statement.
  ?intermediateStatement pq:P582 ?endTime.
 }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?area") v5("?country"):::projected v4("?endTime") v3("?intermediateStatement") v1("?statement") a1((" ")) a2((" ")) a3((" ")) a4((" ")) a5((" ")) c1(["wd:Q6556803"]):::iri f0[["not "]] subgraph f0e0["Exists Clause"] e0c1 --"p:P131"--> e0a1 e0a1 --"p:statement/P131"--> e0a2 e0a2 --"p:P131"--> e0v1 e0v1 --"p:statement/P131"--> e0v2 e0c1 --"p:P131"--> e0a3 e0a3 --"p:statement/P131"--> e0a4 e0a4 --"p:P131"--> e0v3 e0v3 --"p:statement/P131"--> e0a5 e0a5 --"p:P131"--> e0v1 e0v3 --"p:qualifier/P582"--> e0v4 e0v2("?area"):::projected e0v4("?endTime"):::projected e0v3("?intermediateStatement"):::projected e0v1("?statement"):::projected e0a1((" ")):::projected e0a2((" ")):::projected e0a3((" ")):::projected e0a4((" ")):::projected e0a5((" ")):::projected e0c1(["wd:Q6556803"]):::iri end f0--EXISTS--> f0e0 f0 --> c1 f0 --> c2 f0 --> a1 f0 --> c3 f0 --> a2 f0 --> v1 f0 --> v2 f0 --> a3 f0 --> a4 f0 --> v3 f0 --> a5 f0 --> c4 f0 --> v4 c1 --"p:P131"--> a1 a1 --"p:statement/P131"--> a2 a2 --"p:P131"--> v1 v1 --"p:statement/P131"--> v2 c1 --"p:P131"--> a3 a3 --"p:statement/P131"--> a4 a4 --"p:P131"--> v3 v3 --"p:statement/P131"--> a5 a5 --"p:P131"--> v1 v3 --"p:qualifier/P582"--> v4 c1 --"p:direct/P131"--> v2 v2 --"p:direct/P17"--> v5