import sys from collections import defaultdict as DD from itertools import combinations as comb D = DD(set) for i in sys.stdin.read().strip().split('\n'): a, b = i.split("-") D[a].add(b) D[b].add(a) for k, v in D.items(): for i in v: w = v - {i} if all(b in D[a] for a,b in comb(w,2)): print(",".join(sorted({k}|w))) #sys.exit(0)