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

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

m = A("m")
n = B("n")
a = B("a")
l = B("l")
e = A("e")
c = A("c")

m.z = c
n.p = a
n.q = a
a.p = n
a.q = l
l.p = a
l.q = a
e.z = m
c.z = e
assert m.z.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

m = A("m")
n = B("n")
a = B("a")
l = B("l")
e = A("e")
c = A("c")

m.z = c
n.p = a
n.q = a
a.p = n
a.q = l
l.p = a
l.q = a
e.z = m
c.z = e
assert m.z.z.z.z.z.z.txt == "m"