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

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

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

c = A("c")
l = B("l")
m = C("m")
a = A("a")

c.u = a
c.x = l
l.w = m
m.s = c
m.p = c
m.o = l
a.u = c
a.x = l
assert m.o.w.s.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.x: B = None
        self.txt = txt

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

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

c = A("c")
l = B("l")
m = C("m")
a = A("a")

c.u = a
c.x = l
l.w = m
m.s = c
m.p = c
m.o = l
a.u = c
a.x = l
assert m.o.w.s.txt == "c"