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

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

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

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

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

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

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

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

m.q = n
m.x = n
n.r = m
n.p = m
a.w = n
assert n.r.x.p.txt == "m"