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

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

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

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

a.x = b
m.r = a
m.x = a
m.w = a
f.u = a
b.r = a
b.x = a
b.w = a
e.u = a
k.r = a
k.x = a
k.w = a
assert m.x.x.w.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

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

a.x = b
m.r = a
m.x = a
m.w = a
f.u = a
b.r = a
b.x = a
b.w = a
e.u = a
k.r = a
k.x = a
k.w = a
assert m.x.x.w.x.r.txt == "a"