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

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

j = A("j")
b = B("b")
f = A("f")
a = B("a")
k = A("k")

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

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

j = A("j")
b = B("b")
f = A("f")
a = B("a")
k = A("k")

j.o = b
b.z = a
f.o = b
a.z = b
k.o = a
assert j.o.z.z.z.z.txt == "b"