query: SELECT (wd:Q5 as ?item)  (COUNT(DISTINCT ?relative) as ?descendants) WITH {SELECT DISTINCT ?item {
    ?item (wdt:P20|(p:P20/pq:P131)) ?dp. ?dp wdt:P30 wd:Q49. ?dp wdt:P31/wdt:P279* wd:Q133156.
    ?item wdt:P19 ?bp. ?bp wdt:P17/wdt:P30 wd:Q46.
    ?item wdt:P40 [].
    ?item (wdt:P22|wdt:P25)/(wdt:P22|wdt:P25) [].
  } } AS %t1 WITH {
  SELECT DISTINCT ?item
  {
      INCLUDE %t1 .
      ?item (wdt:P22|wdt:P25)+ ?ancestor .
      ?ancestor p:P39 ?as.
      ?as ps:P39 ?pos; pq:P582 ?ed.
    FILTER(?pos IN (wd:Q18810062,wd:Q18810063))
  } 
  } AS %t2 WHERE {
      INCLUDE %t2 .
    ?item (wdt:P40)+ ?relative 
  }