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

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

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

b = A("b")
n = B("n")
a = C("a")

b.w = n
n.w = a
n.p = b
a.r = b
a.w = b
a.x = b
assert a.w.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

b = A("b")
n = B("n")
a = C("a")

b.w = n
n.w = a
n.p = b
a.r = b
a.w = b
a.x = b
assert a.w.w.p.txt == "b"