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

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

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

a = A("a")
b = B("b")
f = C("f")
h = C("h")

a.p = b
b.z = a
f.z = h
f.o = b
f.x = b
h.z = f
h.o = b
h.x = b
assert b.z.p.z.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

a = A("a")
b = B("b")
f = C("f")
h = C("h")

a.p = b
b.z = a
f.z = h
f.o = b
f.x = b
h.z = f
h.o = b
h.x = b
assert b.z.p.z.txt == "a"