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

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

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

h = A("h")
i = B("i")
b = C("b")
d = B("d")
a = C("a")

h.p = b
i.y = d
i.z = h
b.p = i
d.y = i
d.z = h
a.p = i
assert a.p.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

h = A("h")
i = B("i")
b = C("b")
d = B("d")
a = C("a")

h.p = b
i.y = d
i.z = h
b.p = i
d.y = i
d.z = h
a.p = i
assert a.p.y.z.txt == "h"