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

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

a = A("a")
f = B("f")
l = B("l")
n = A("n")

a.z = n
f.p = a
l.p = a
n.z = a
assert l.p.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: A = None
        self.txt = txt

a = A("a")
f = B("f")
l = B("l")
n = A("n")

a.z = n
f.p = a
l.p = a
n.z = a
assert l.p.z.z.z.txt == "n"