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

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

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

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

j.p = f
j.x = f
i.w = j
f.x = j
f.t = i
f.q = i
assert j.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.x: C = None
        self.txt = txt

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

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

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

j.p = f
j.x = f
i.w = j
f.x = j
f.t = i
f.q = i
assert j.x.x.x.txt == "f"