query: SELECT ?item ?itemLabel ?level ?rgb ?class ?classLabel WHERE {
  {SELECT DISTINCT ?item ?level ?rgb ?class WHERE {
    { {SELECT ?item ?level ?class ?rgb WHERE { ?item wdt:P9622 []. ?item wdt:P31 ?class . } } BIND("work" AS ?level) BIND("ff0000" AS ?rgb) } UNION
    { {SELECT ?item ?level ?class ?rgb WHERE { ?publisher wdt:P9624 []. ?item wdt:P123 ?publisher ; p:P527 [ps:P527 ?p_series ; pq:P1545 ?series]. ?item wdt:P31 ?class .} } BIND("work" AS ?level) BIND("ff0000" AS ?rgb) } UNION
    { {SELECT ?item ?level ?class ?rgb WHERE { ?work wdt:P9622 []. {?work wdt:P4969 ?item} UNION {?item wdt:P144 ?work} UNION {?item wdt:P6524 ?work}. ?item wdt:P31 ?class .} } BIND("expression" AS ?level) BIND("008000" AS ?rgb) } UNION 
    { {SELECT ?item ?level ?class ?rgb WHERE { ?publisher wdt:P9624 []. ?periodical wdt:P123 ?publisher ; p:P527 [ps:P527 ?item ; pq:P1545 ?series]. ?item wdt:P31 ?class .} } BIND("expression" AS ?level) BIND("008000" AS ?rgb) } UNION
    { {SELECT ?item ?level ?class ?rgb WHERE { ?work wdt:P9622 []. {?work wdt:P4969 ?expression} UNION {?expression wdt:P144 ?work} UNION {?expression wdt:P6524 ?work}. 
                                              ?item ( wdt:P5059 | wdt:P9745 ) ?expression . ?item wdt:P31 ?class . } } BIND("adaptation" AS ?level) BIND("ffffcc" AS ?rgb) } UNION
    { {SELECT ?item ?level ?class ?rgb WHERE { ?work wdt:P9622 []. {?work wdt:P747 ?item . } UNION { ?item wdt:P629 ?work . } UNION {?item wdt:P2550 ?work} 
                                              ?item wdt:P31 ?class . } } BIND("manifestation" AS ?level) BIND("0000ff" AS ?rgb) } UNION 
    { {SELECT ?item ?level ?class ?rgb WHERE {?work wdt:P9622 []. {?work wdt:P4969 ?expression} UNION {?expression wdt:P144 ?work} UNION {?expression wdt:P6524 ?work} . 
                                              ?adaptation ( wdt:P5059 | wdt:P9745 ) ?expression .{?adaptation wdt:P747 ?item} UNION {?item wdt:P629 ?adaptation} UNION {?item wdt:P2550 ?adaptation} .
                                              ?item wdt:P31 ?class . } } BIND("manifestation" AS ?level) BIND("0000ff" AS ?rgb) } UNION 
    { {SELECT ?item ?level ?class ?rgb WHERE { ?work wdt:P9622 []. {?work wdt:P4969 ?expression} UNION {?expression wdt:P144 ?work} UNION {?expression wdt:P6524 ?work}. 
                                              {?expression wdt:P747 ?item} UNION {?item wdt:P629 ?expression} UNION {?item wdt:P2550 ?expression} . 
                                              ?item wdt:P31 ?class . } } BIND("manifestation" AS ?level) BIND("0000ff" AS ?rgb) } 
    } }
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
   # VALUES ?prop { wdt:P629 wdt:P144 wdt:P9745 wdt:P2550 wdt:P747 wdt:P4969 wdt:P6524 wdt:P5059 wdt:P1433 }
    }