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

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

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

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

i.s = g
c.w = i
c.o = d
c.s = d
d.x = i
d.o = g
g.w = i
g.o = d
g.s = d
assert c.w.s.w.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

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

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

i.s = g
c.w = i
c.o = d
c.s = d
d.x = i
d.o = g
g.w = i
g.o = d
g.s = d
assert c.w.s.w.txt == "i"