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

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

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

a = A("a")
m = B("m")
j = C("j")
n = B("n")

a.y = m
m.w = a
m.z = j
m.p = j
j.p = m
n.w = a
n.z = j
n.p = j
assert m.z.p.w.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

a = A("a")
m = B("m")
j = C("j")
n = B("n")

a.y = m
m.w = a
m.z = j
m.p = j
j.p = m
n.w = a
n.z = j
n.p = j
assert m.z.p.w.y.txt == "m"