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

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

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

l = A("l")
b = B("b")
f = C("f")
d = B("d")
e = A("e")
m = C("m")

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

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

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

l = A("l")
b = B("b")
f = C("f")
d = B("d")
e = A("e")
m = C("m")

l.s = d
l.r = m
b.p = l
f.u = l
d.p = l
e.s = b
e.r = f
m.u = e
assert d.p.r.u.r.u.txt == "l"