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

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

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

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

j.q = f
j.x = m
i.x = j
f.s = j
f.r = m
f.z = m
m.s = j
m.r = f
m.z = f
assert f.r.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.x: C = None
        self.txt = txt

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

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

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

j.q = f
j.x = m
i.x = j
f.s = j
f.r = m
f.z = m
m.s = j
m.r = f
m.z = f
assert f.r.s.x.txt == "m"