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

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

e = A("e")
f = B("f")
m = B("m")
c = B("c")
i = A("i")
h = B("h")

e.s = c
e.z = h
f.y = h
m.y = h
c.y = h
i.s = m
i.z = h
h.y = c
assert m.y.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.z: B = None
        self.txt = txt

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

e = A("e")
f = B("f")
m = B("m")
c = B("c")
i = A("i")
h = B("h")

e.s = c
e.z = h
f.y = h
m.y = h
c.y = h
i.s = m
i.z = h
h.y = c
assert m.y.y.y.y.y.y.txt == "c"