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

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

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

m = A("m")
f = B("f")
d = C("d")

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

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

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

m = A("m")
f = B("f")
d = C("d")

m.p = f
m.r = f
f.u = m
d.o = f
assert d.o.u.r.txt == "f"