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

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

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

f = A("f")
j = B("j")
m = C("m")
b = C("b")

f.o = j
j.q = m
j.x = f
j.s = f
m.o = f
m.q = b
b.o = f
b.q = m
assert j.s.o.s.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

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

f = A("f")
j = B("j")
m = C("m")
b = C("b")

f.o = j
j.q = m
j.x = f
j.s = f
m.o = f
m.q = b
b.o = f
b.q = m
assert j.s.o.s.txt == "f"