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.txt = txt

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

h.z = l
c.p = m
m.p = n
n.p = c
l.z = e
e.z = h
j.z = h
k.z = j
assert e.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.txt = txt

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

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