query: SELECT ?stateLabel ?item1 ?item1Label ?item2 ?item2Label
  WITH {
    SELECT DISTINCT ?state WHERE {
      ?state wdt:P31/wdt:P279* wd:Q3624078;
             p:P463 ?memberOfStatement.
      ?memberOfStatement a wikibase:BestRank;
                           ps:P463 wd:Q1065.
      MINUS { ?memberOfStatement pq:P582 ?endTime. }
      MINUS { ?state wdt:P576|wdt:P582 ?end. }
    }
  } AS %states
  WHERE {
    INCLUDE %states.
    ?state wdt:P1906 ?position.
    ?item1 wdt:P31 wd:Q5;
           wdt:P39 ?position;
           wdt:P734/wdt:P1705 ?familyName1.
    ?item2 wdt:P31 wd:Q5;
           wdt:P39 ?position;
           wdt:P734/wdt:P1705 ?familyName2.
    FILTER(STR(?item1) < STR(?item2))
    FILTER(SUBSTR(?familyName1, 1, 4) = SUBSTR(?familyName2, 1, 4))
    FILTER(?familyName1 != ?familyName2)
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  }
  ORDER BY ?stateLabel