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

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

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

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

c.p = g
c.z = h
d.o = g
d.w = h
d.s = h
h.o = d
g.p = c
g.z = h
assert c.p.p.z.o.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.z: C = None
        self.txt = txt

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

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

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

c.p = g
c.z = h
d.o = g
d.w = h
d.s = h
h.o = d
g.p = c
g.z = h
assert c.p.p.z.o.txt == "d"