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

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

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

f = A("f")
j = B("j")
h = C("h")

f.o = j
j.w = f
j.x = h
h.w = f
h.q = f
h.p = j
assert f.o.w.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

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

f = A("f")
j = B("j")
h = C("h")

f.o = j
j.w = f
j.x = h
h.w = f
h.q = f
h.p = j
assert f.o.w.o.txt == "j"