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

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

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

b = A("b")
c = B("c")
m = C("m")

b.p = c
b.w = m
c.q = m
m.z = b
m.r = b
assert c.q.r.w.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.w: C = None
        self.txt = txt

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

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

b = A("b")
c = B("c")
m = C("m")

b.p = c
b.w = m
c.q = m
m.z = b
m.r = b
assert c.q.r.w.txt == "m"