query: PREFIX wd: <http://www.wikidata.org/entity/>
  PREFIX wdt: <http://www.wikidata.org/prop/direct/>
  PREFIX wikibase: <http://wikiba.se/ontology#>
  PREFIX p: <http://www.wikidata.org/prop/>
  PREFIX v: <http://www.wikidata.org/prop/statement/>
  PREFIX q: <http://www.wikidata.org/prop/qualifier/>
  PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
  PREFIX ps: <http://www.wikidata.org/prop/statement/>
  PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
  
    # Query to find the classes of items that are
    # most often connected by the property ?p = P836
    # Query generated by [[Template:MostConnectedClasses]]
  
      SELECT ?item ?itemLabel (SAMPLE(?nuts) AS ?nuts) 
              (SAMPLE(?gss) AS ?gss) (SAMPLE(?iso3166_2) AS ?iso3166_2) 
              (GROUP_CONCAT(DISTINCT(?class_label); separator = "; ") AS ?class_list) 
      WHERE {
         ?item wdt:P605 ?nuts .
         ?item wdt:P17 wd:Q145 .
         ?item wdt:P31 ?class .
         ?class rdfs:label ?class_label filter (lang(?class_label) = "en") .
         OPTIONAL { ?item wdt:P836 ?gss  }
         OPTIONAL { ?item wdt:P300 ?iso3166_2  }
        
         SERVICE wikibase:label {
            bd:serviceParam wikibase:language "en" .
         }
      } GROUP BY ?item ?itemLabel
      ORDER BY ?nuts