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

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

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

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

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

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

d.y = e
d.s = b
f.p = e
e.y = a
e.s = h
c.y = h
c.s = a
m.y = d
m.s = h
b.y = m
b.s = a
a.y = e
a.s = m
i.p = m
h.y = d
h.s = b
assert h.y.y.s.s.y.txt == "m"