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

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

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

b = A("b")
m = B("m")
k = C("k")
j = A("j")

b.x = m
b.u = j
m.u = k
m.z = k
k.w = m
k.z = b
j.x = m
j.u = b
assert j.x.z.z.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.u: A = None
        self.txt = txt

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

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

b = A("b")
m = B("m")
k = C("k")
j = A("j")

b.x = m
b.u = j
m.u = k
m.z = k
k.w = m
k.z = b
j.x = m
j.u = b
assert j.x.z.z.x.txt == "m"