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

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

l = A("l")
f = B("f")
g = A("g")
d = A("d")
c = B("c")
m = B("m")
h = A("h")

l.z = f
f.s = m
g.z = m
d.z = f
c.s = f
m.s = f
h.z = c
assert c.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

l = A("l")
f = B("f")
g = A("g")
d = A("d")
c = B("c")
m = B("m")
h = A("h")

l.z = f
f.s = m
g.z = m
d.z = f
c.s = f
m.s = f
h.z = c
assert c.s.s.s.s.txt == "m"