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

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

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

g = A("g")
m = B("m")
k = C("k")

g.s = k
m.w = g
m.s = k
k.o = g
assert k.o.s.o.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

g = A("g")
m = B("m")
k = C("k")

g.s = k
m.w = g
m.s = k
k.o = g
assert k.o.s.o.txt == "g"