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

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

b = A("b")
j = B("j")
a = B("a")
m = B("m")
h = B("h")
i = B("i")
d = B("d")

b.s = j
j.z = i
j.s = i
a.z = i
a.s = d
m.z = d
m.s = j
h.z = i
h.s = d
i.z = j
i.s = h
d.z = m
d.s = h
assert m.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

b = A("b")
j = B("j")
a = B("a")
m = B("m")
h = B("h")
i = B("i")
d = B("d")

b.s = j
j.z = i
j.s = i
a.z = i
a.s = d
m.z = d
m.s = j
h.z = i
h.s = d
i.z = j
i.s = h
d.z = m
d.s = h
assert m.z.z.z.txt == "d"