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

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

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

h = A("h")
b = B("b")
g = C("g")
d = A("d")

h.z = g
b.r = h
b.p = d
g.v = b
d.z = g
assert b.p.z.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

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

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

h = A("h")
b = B("b")
g = C("g")
d = A("d")

h.z = g
b.r = h
b.p = d
g.v = b
d.z = g
assert b.p.z.v.r.txt == "h"