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

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

b = A("b")
l = B("l")
e = B("e")
a = B("a")
h = B("h")
d = A("d")
m = A("m")

b.p = a
l.u = m
e.u = d
a.u = m
h.u = b
d.p = h
m.p = l
assert m.p.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

b = A("b")
l = B("l")
e = B("e")
a = B("a")
h = B("h")
d = A("d")
m = A("m")

b.p = a
l.u = m
e.u = d
a.u = m
h.u = b
d.p = h
m.p = l
assert m.p.u.p.txt == "l"