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

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

l = A("l")
h = B("h")
m = B("m")
c = B("c")
a = B("a")
e = A("e")

l.r = e
l.s = e
h.p = m
m.p = h
c.p = h
a.p = c
e.r = l
e.s = l
assert c.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.s: A = None
        self.txt = txt

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

l = A("l")
h = B("h")
m = B("m")
c = B("c")
a = B("a")
e = A("e")

l.r = e
l.s = e
h.p = m
m.p = h
c.p = h
a.p = c
e.r = l
e.s = l
assert c.p.p.p.txt == "h"