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

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

b = A("b")
f = B("f")
h = B("h")
i = A("i")
a = B("a")

b.z = f
f.o = b
h.o = i
i.z = f
a.o = b
assert b.z.o.z.o.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

b = A("b")
f = B("f")
h = B("h")
i = A("i")
a = B("a")

b.z = f
f.o = b
h.o = i
i.z = f
a.o = b
assert b.z.o.z.o.z.txt == "f"