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

n = A("n")
m = B("m")
j = A("j")
a = B("a")
g = B("g")
i = B("i")
l = B("l")

n.z = j
m.p = l
j.z = n
a.p = m
g.p = i
i.p = l
l.p = g
assert l.p.p.p.p.p.p.p.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

n = A("n")
m = B("m")
j = A("j")
a = B("a")
g = B("g")
i = B("i")
l = B("l")

n.z = j
m.p = l
j.z = n
a.p = m
g.p = i
i.p = l
l.p = g
assert l.p.p.p.p.p.p.p.txt == "g"