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.r: B = None
        self.txt = txt

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

l.z = m
a.p = c
a.r = e
n.p = c
n.r = j
k.z = l
e.p = l
e.r = a
j.p = m
j.r = e
c.z = l
m.z = k
assert n.p.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: A = None
        self.r: B = None
        self.txt = txt

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

l.z = m
a.p = c
a.r = e
n.p = c
n.r = j
k.z = l
e.p = l
e.r = a
j.p = m
j.r = e
c.z = l
m.z = k
assert n.p.z.z.z.z.z.txt == "m"