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

k = A("k")
b = B("b")
g = A("g")
e = B("e")
f = B("f")
d = A("d")
c = B("c")
m = A("m")

k.o = b
b.z = e
g.o = f
e.z = f
f.z = e
d.o = f
c.z = f
m.o = f
assert d.o.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

k = A("k")
b = B("b")
g = A("g")
e = B("e")
f = B("f")
d = A("d")
c = B("c")
m = A("m")

k.o = b
b.z = e
g.o = f
e.z = f
f.z = e
d.o = f
c.z = f
m.o = f
assert d.o.z.z.z.txt == "e"