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

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

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

f = A("f")
i = B("i")
l = C("l")
d = A("d")
c = C("c")

f.q = l
f.t = d
f.z = c
i.t = f
i.u = c
l.w = i
l.r = c
d.q = c
d.t = f
d.z = l
c.w = i
c.r = l
assert d.q.w.t.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.t: A = None
        self.z: C = None
        self.txt = txt

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

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

f = A("f")
i = B("i")
l = C("l")
d = A("d")
c = C("c")

f.q = l
f.t = d
f.z = c
i.t = f
i.u = c
l.w = i
l.r = c
d.q = c
d.t = f
d.z = l
c.w = i
c.r = l
assert d.q.w.t.txt == "f"