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

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

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

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

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

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

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

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

n.z = m
n.r = j
n.q = j
j.y = n
j.p = n
j.w = n
m.u = n
m.r = n
assert j.p.r.y.txt == "n"