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

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

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

b = A("b")
f = B("f")
j = C("j")
k = C("k")
d = B("d")

b.u = d
b.w = j
f.y = d
f.w = d
f.s = k
j.x = b
k.x = b
d.y = f
d.w = f
d.s = k
assert b.u.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.w: C = None
        self.txt = txt

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

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

b = A("b")
f = B("f")
j = C("j")
k = C("k")
d = B("d")

b.u = d
b.w = j
f.y = d
f.w = d
f.s = k
j.x = b
k.x = b
d.y = f
d.w = f
d.s = k
assert b.u.s.x.txt == "b"