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

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

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

m = A("m")
g = B("g")
l = C("l")

m.t = g
g.p = l
l.v = g
l.r = m
l.p = m
assert g.p.p.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

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

m = A("m")
g = B("g")
l = C("l")

m.t = g
g.p = l
l.v = g
l.r = m
l.p = m
assert g.p.p.t.txt == "g"