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

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

class C:
    def __init__(self, txt: str):
        self.t: A = None
        self.x: A = None
        self.p: A = None
        self.txt = txt

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

m.s = a
a.r = m
f.t = m
f.x = m
f.p = m
assert f.p.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.t: A = None
        self.x: A = None
        self.p: A = None
        self.txt = txt

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

m.s = a
a.r = m
f.t = m
f.x = m
f.p = m
assert f.p.s.r.txt == "m"