query: SELECT ?grouping (COUNT(DISTINCT ?entity) as ?count) (SAMPLE(?entity) as ?sample) WHERE { ?entity wdt:P31/wdt:P279* wd:Q2879 .
    MINUS { ?entity wdt:P576 ?abolished }
    OPTIONAL { 
      ?entity p:P131 ?inStatement .
      ?inStatement a wikibase:BestRank ; ps:P131 ?in .
      FILTER NOT EXISTS { ?inStatement wdt:P582 [] }
    }
    OPTIONAL { 
      ?entity p:P17 ?countryStatement .
      ?countryStatement a wikibase:BestRank ; ps:P17 ?country .
      FILTER NOT EXISTS { ?countryStatement wdt:P582 [] }
    }. ?entity wdt:P31 ?grouping .} GROUP BY ?grouping HAVING (?count >= 1) ORDER BY DESC(?count) LIMIT 1000