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

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

h = A("h")
b = B("b")
f = B("f")
e = A("e")

h.o = e
h.y = e
b.t = h
b.y = f
f.t = h
f.y = b
e.o = h
e.y = h
assert e.o.y.o.y.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.y: A = None
        self.txt = txt

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

h = A("h")
b = B("b")
f = B("f")
e = A("e")

h.o = e
h.y = e
b.t = h
b.y = f
f.t = h
f.y = b
e.o = h
e.y = h
assert e.o.y.o.y.txt == "e"