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

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

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

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

b.r = d
b.t = d
b.p = d
d.v = b
d.s = b
f.v = d
assert d.s.r.v.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.t: B = None
        self.p: B = None
        self.txt = txt

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

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

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

b.r = d
b.t = d
b.p = d
d.v = b
d.s = b
f.v = d
assert d.s.r.v.txt == "b"