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

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

l = A("l")
a = B("a")
i = B("i")
f = B("f")
j = B("j")
e = A("e")
m = A("m")
h = A("h")
d = A("d")
n = A("n")

l.z = a
a.x = n
i.x = l
f.x = n
j.x = h
e.z = i
m.z = a
h.z = a
d.z = j
n.z = i
assert n.z.x.z.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

l = A("l")
a = B("a")
i = B("i")
f = B("f")
j = B("j")
e = A("e")
m = A("m")
h = A("h")
d = A("d")
n = A("n")

l.z = a
a.x = n
i.x = l
f.x = n
j.x = h
e.z = i
m.z = a
h.z = a
d.z = j
n.z = i
assert n.z.x.z.x.z.txt == "i"