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

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

n = A("n")
i = B("i")
c = B("c")
m = B("m")

n.x = m
i.z = c
i.q = c
c.z = m
c.q = m
m.z = i
m.q = i
assert i.q.z.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

n = A("n")
i = B("i")
c = B("c")
m = B("m")

n.x = m
i.z = c
i.q = c
c.z = m
c.q = m
m.z = i
m.q = i
assert i.q.z.q.z.txt == "c"