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

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

c = A("c")
e = B("e")
a = A("a")
h = A("h")
m = A("m")
j = B("j")

c.y = j
e.x = j
e.z = j
a.y = j
h.y = e
m.y = j
j.x = e
j.z = e
assert m.y.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

c = A("c")
e = B("e")
a = A("a")
h = A("h")
m = A("m")
j = B("j")

c.y = j
e.x = j
e.z = j
a.y = j
h.y = e
m.y = j
j.x = e
j.z = e
assert m.y.z.z.z.txt == "e"