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

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

k = A("k")
m = B("m")
a = B("a")
j = B("j")
f = A("f")
d = B("d")

k.y = a
k.z = f
m.u = d
a.u = m
j.u = d
f.y = a
f.z = k
d.u = j
assert a.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.z: A = None
        self.txt = txt

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

k = A("k")
m = B("m")
a = B("a")
j = B("j")
f = A("f")
d = B("d")

k.y = a
k.z = f
m.u = d
a.u = m
j.u = d
f.y = a
f.z = k
d.u = j
assert a.u.u.u.u.u.txt == "j"