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

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

n = A("n")
g = B("g")
b = B("b")
f = B("f")
d = A("d")
m = B("m")
c = B("c")
a = A("a")
i = B("i")
e = B("e")

n.y = e
n.u = a
g.z = b
b.z = f
f.z = m
d.y = m
d.u = n
m.z = i
c.z = b
a.y = i
a.u = n
i.z = e
e.z = g
assert c.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.u: A = None
        self.txt = txt

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

n = A("n")
g = B("g")
b = B("b")
f = B("f")
d = A("d")
m = B("m")
c = B("c")
a = A("a")
i = B("i")
e = B("e")

n.y = e
n.u = a
g.z = b
b.z = f
f.z = m
d.y = m
d.u = n
m.z = i
c.z = b
a.y = i
a.u = n
i.z = e
e.z = g
assert c.z.z.z.z.txt == "i"