query: SELECT distinct ?item  ?hill_name ?cat_name WITH {
  SELECT distinct ?cat_item  ?cat_name 
  WHERE { 
    SERVICE wikibase:mwapi {
       bd:serviceParam wikibase:endpoint "en.wikipedia.org";
                       wikibase:api "Generator";
                       mwapi:generator "categorymembers";
                       mwapi:gcmtitle "Category:Mountains and hills of Scotland by council area" ;         # specifically here
                       mwapi:gcmprop "ids|title|type";
                       mwapi:gcmlimit "max".
       # out
       ?cat_name wikibase:apiOutput mwapi:title.        # en-wikipedia article / category name
       ?cat_item wikibase:apiOutputItem mwapi:item.            # wikidata QId for the person's item
      }
  } } as %i
  WHERE
  {
    INCLUDE %i
    SERVICE wikibase:mwapi {
                                        # in - feed all the ?cat_title to MWAPI
       bd:serviceParam wikibase:endpoint "en.wikipedia.org";
                       wikibase:api "Generator";
                       mwapi:generator "categorymembers";
                       mwapi:gcmtitle ?cat_name ;         # specifically here
                       mwapi:gcmprop "ids|title|type";
                       mwapi:gcmlimit "max".
       # out
       ?hill_name wikibase:apiOutput mwapi:title.        # en-wikipedia article / category name
       ?item wikibase:apiOutputItem mwapi:item.            # wikidata QId for the person's item
      }
  
  }