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

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

d = A("d")
h = B("h")
b = B("b")
l = A("l")
f = A("f")
c = A("c")
a = A("a")
n = B("n")

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

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

d = A("d")
h = B("h")
b = B("b")
l = A("l")
f = A("f")
c = A("c")
a = A("a")
n = B("n")

d.s = h
d.y = a
h.z = a
b.z = c
l.s = n
l.y = f
f.s = n
f.y = a
c.s = h
c.y = a
a.s = n
a.y = c
n.z = f
assert h.z.s.z.y.s.txt == "n"