query: SELECT (count(DISTINCT ?categoryItem ) as ?total) WHERE {
      # ?article and ?category share the same P373 ("Commons Category")
      ?articleItem  wdt:P373 ?commonsCategory .
      ?categoryItem wdt:P373 ?commonsCategory .
    
      # P301 and P910 are set properly
      ?articleItem  wdt:P910 ?categoryItem .
      ?categoryItem wdt:P301 ?articleItem  .
    
      # sitelink to Commons points to the same category as property P373
      ?commonsSitelink schema:about ?categoryItem .
      FILTER(STRSTARTS(STR(?commonsSitelink), "https://commons.wikimedia.org/wiki/Category"))
      FILTER(STRENDS(STR(?commonsSitelink), ENCODE_FOR_URI(?commonsCategory)))
  }