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

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

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

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

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

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

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

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

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