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

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

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

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

m.p = a
a.u = m
a.y = m
b.q = m
assert b.q.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

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

m.p = a
a.u = m
a.y = m
b.q = m
assert b.q.p.y.txt == "m"