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

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

n = A("n")
b = B("b")
a = B("a")
e = A("e")
d = A("d")
g = A("g")
i = B("i")
l = A("l")
h = B("h")

n.z = d
b.z = a
a.z = b
e.z = g
d.z = e
g.z = d
i.z = h
l.z = g
h.z = a
assert e.z.z.z.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.z: B = None
        self.txt = txt

n = A("n")
b = B("b")
a = B("a")
e = A("e")
d = A("d")
g = A("g")
i = B("i")
l = A("l")
h = B("h")

n.z = d
b.z = a
a.z = b
e.z = g
d.z = e
g.z = d
i.z = h
l.z = g
h.z = a
assert e.z.z.z.z.z.z.z.z.txt == "d"