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

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

a = A("a")
j = B("j")
e = B("e")
i = B("i")
m = A("m")
l = B("l")

a.s = m
a.y = m
j.z = m
e.z = a
i.z = a
m.s = a
m.y = a
l.z = m
assert i.z.s.y.y.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.y: A = None
        self.txt = txt

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

a = A("a")
j = B("j")
e = B("e")
i = B("i")
m = A("m")
l = B("l")

a.s = m
a.y = m
j.z = m
e.z = a
i.z = a
m.s = a
m.y = a
l.z = m
assert i.z.s.y.y.s.txt == "a"