class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.x: C = None
        self.s: C = 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: B = None
        self.txt = txt

b = A("b")
m = B("m")
d = C("d")
e = A("e")

b.p = m
b.x = d
b.s = d
m.w = d
d.s = m
e.p = m
e.x = d
e.s = d
assert m.w.s.w.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.x: C = None
        self.s: C = 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: B = None
        self.txt = txt

b = A("b")
m = B("m")
d = C("d")
e = A("e")

b.p = m
b.x = d
b.s = d
m.w = d
d.s = m
e.p = m
e.x = d
e.s = d
assert m.w.s.w.s.txt == "m"