query: SELECT ?item ?ids (SAMPLE(?painting) AS ?painting) WHERE {
    ?item wdt:P106 wd:Q1028181 .
    ?item wdt:P31 wd:Q5 . 
    ?item wikibase:identifiers ?ids . 
    OPTIONAL { ?painting wdt:P170 ?item } . 
  } GROUP BY ?item ?ids
  ORDER BY DESC(xsd:integer(SUBSTR(STR(?item),STRLEN("http://www.wikidata.org/entity/Q")+1))) 
  LIMIT 300