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

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

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

n = A("n")
i = B("i")
c = C("c")
f = C("f")

n.q = c
i.q = n
i.z = n
c.z = i
c.q = i
c.s = n
f.z = i
f.q = i
f.s = n
assert i.q.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

n = A("n")
i = B("i")
c = C("c")
f = C("f")

n.q = c
i.q = n
i.z = n
c.z = i
c.q = i
c.s = n
f.z = i
f.q = i
f.s = n
assert i.q.q.z.txt == "i"