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

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

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

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

d.v = c
m.z = g
m.p = d
c.p = m
c.u = d
f.z = c
f.p = d
g.p = m
g.u = d
assert d.v.p.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.txt = txt

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

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

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

d.v = c
m.z = g
m.p = d
c.p = m
c.u = d
f.z = c
f.p = d
g.p = m
g.u = d
assert d.v.p.z.p.txt == "m"