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

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

c = A("c")
a = B("a")
m = A("m")
k = A("k")
d = A("d")
b = B("b")

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

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

c = A("c")
a = B("a")
m = A("m")
k = A("k")
d = A("d")
b = B("b")

c.u = a
a.z = k
m.u = b
k.u = a
d.u = a
b.z = m
assert c.u.z.u.txt == "a"