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

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

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

h = A("h")
e = B("e")
g = C("g")
a = B("a")
f = B("f")

h.o = g
e.s = g
e.p = g
g.z = h
a.s = g
a.p = g
f.s = g
f.p = g
assert h.o.z.o.z.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

h = A("h")
e = B("e")
g = C("g")
a = B("a")
f = B("f")

h.o = g
e.s = g
e.p = g
g.z = h
a.s = g
a.p = g
f.s = g
f.p = g
assert h.o.z.o.z.txt == "h"