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

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

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

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

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

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

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

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

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