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

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

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

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

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

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

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