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

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

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

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

c.p = n
c.r = n
n.s = m
m.s = c
m.x = c
assert c.p.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.r: B = None
        self.txt = txt

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

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

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

c.p = n
c.r = n
n.s = m
m.s = c
m.x = c
assert c.p.s.x.txt == "c"