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

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

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

h = A("h")
c = B("c")
f = C("f")
i = C("i")

h.z = c
c.p = h
f.r = c
f.v = h
i.r = c
i.v = h
assert c.p.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

h = A("h")
c = B("c")
f = C("f")
i = C("i")

h.z = c
c.p = h
f.r = c
f.v = h
i.r = c
i.v = h
assert c.p.z.p.txt == "h"