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

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

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

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

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

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

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

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

a.y = n
a.w = n
n.p = m
n.t = m
n.v = a
m.x = n
m.q = n
assert m.q.t.q.txt == "n"