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

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

d = A("d")
k = B("k")
h = A("h")
l = B("l")
e = A("e")
b = B("b")
i = A("i")

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

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

d = A("d")
k = B("k")
h = A("h")
l = B("l")
e = A("e")
b = B("b")
i = A("i")

d.z = b
k.u = d
k.p = h
h.z = l
l.u = i
l.p = i
e.z = l
b.u = e
b.p = d
i.z = l
assert e.z.p.z.u.z.txt == "l"