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

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

class C:
    def __init__(self, txt: str):
        self.y: B = None
        self.x: B = None
        self.txt = txt

l = A("l")
f = B("f")
m = C("m")
b = A("b")
a = A("a")
k = A("k")

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

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

class C:
    def __init__(self, txt: str):
        self.y: B = None
        self.x: B = None
        self.txt = txt

l = A("l")
f = B("f")
m = C("m")
b = A("b")
a = A("a")
k = A("k")

l.s = f
f.u = m
f.z = b
m.y = f
m.x = f
b.s = f
a.s = f
k.s = f
assert a.s.u.x.txt == "f"