class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

h = A("h")
b = B("b")
e = B("e")
k = A("k")
g = A("g")

h.w = k
b.o = g
e.o = h
k.w = h
g.w = h
assert h.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

h = A("h")
b = B("b")
e = B("e")
k = A("k")
g = A("g")

h.w = k
b.o = g
e.o = h
k.w = h
g.w = h
assert h.w.w.w.w.txt == "h"