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

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

d = A("d")
e = B("e")
c = B("c")
m = B("m")

d.r = c
d.u = e
e.p = c
c.p = e
m.p = e
assert e.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.u: B = None
        self.txt = txt

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

d = A("d")
e = B("e")
c = B("c")
m = B("m")

d.r = c
d.u = e
e.p = c
c.p = e
m.p = e
assert e.p.p.p.txt == "c"