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

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

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

d = A("d")
c = B("c")
a = C("a")
b = C("b")
g = B("g")

d.p = g
d.v = g
c.v = b
a.r = d
a.y = d
a.z = b
b.r = d
b.y = d
b.z = a
g.v = a
assert d.p.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.v: B = None
        self.txt = txt

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

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

d = A("d")
c = B("c")
a = C("a")
b = C("b")
g = B("g")

d.p = g
d.v = g
c.v = b
a.r = d
a.y = d
a.z = b
b.r = d
b.y = d
b.z = a
g.v = a
assert d.p.v.r.txt == "d"