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

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

l = A("l")
k = B("k")
g = A("g")
j = B("j")
d = A("d")
a = B("a")

l.z = d
k.p = d
k.u = g
g.z = l
j.p = g
j.u = g
d.z = g
a.p = d
a.u = g
assert a.u.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.p: A = None
        self.u: A = None
        self.txt = txt

l = A("l")
k = B("k")
g = A("g")
j = B("j")
d = A("d")
a = B("a")

l.z = d
k.p = d
k.u = g
g.z = l
j.p = g
j.u = g
d.z = g
a.p = d
a.u = g
assert a.u.z.z.z.z.txt == "l"