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

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

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

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

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

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

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

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

f.z = m
j.q = f
j.z = i
m.w = i
m.q = j
i.w = m
i.q = j
assert i.q.q.z.w.txt == "i"