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

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

h = A("h")
d = B("d")
l = B("l")
i = A("i")
g = A("g")
f = A("f")
e = B("e")
k = B("k")
a = A("a")

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

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

h = A("h")
d = B("d")
l = B("l")
i = A("i")
g = A("g")
f = A("f")
e = B("e")
k = B("k")
a = A("a")

h.x = e
h.p = g
d.z = k
l.z = k
i.x = l
i.p = a
g.x = e
g.p = i
f.x = e
f.p = g
e.z = d
k.z = e
a.x = l
a.p = i
assert k.z.z.z.z.z.z.z.z.z.txt == "k"