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

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

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

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

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

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

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

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

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