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

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

n = A("n")
g = B("g")
l = B("l")
a = B("a")
b = B("b")
f = A("f")
i = A("i")

n.z = f
g.u = b
l.u = a
a.u = g
b.u = g
f.z = n
i.z = n
assert b.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

n = A("n")
g = B("g")
l = B("l")
a = B("a")
b = B("b")
f = A("f")
i = A("i")

n.z = f
g.u = b
l.u = a
a.u = g
b.u = g
f.z = n
i.z = n
assert b.u.u.u.u.u.txt == "g"