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

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

k = A("k")
d = B("d")
b = B("b")
i = A("i")
e = A("e")

k.z = b
d.x = b
b.x = d
i.z = d
e.z = b
assert k.z.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

k = A("k")
d = B("d")
b = B("b")
i = A("i")
e = A("e")

k.z = b
d.x = b
b.x = d
i.z = d
e.z = b
assert k.z.x.x.x.x.txt == "b"