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

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

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

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

m.p = n
m.x = d
m.v = d
d.z = m
d.q = m
e.r = d
e.y = d
e.w = d
n.p = m
n.x = d
n.v = d
assert n.v.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.x: B = None
        self.v: B = None
        self.txt = txt

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

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

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

m.p = n
m.x = d
m.v = d
d.z = m
d.q = m
e.r = d
e.y = d
e.w = d
n.p = m
n.x = d
n.v = d
assert n.v.z.p.txt == "n"