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

class B:
    def __init__(self, txt: str):
        self.q: 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")
d = C("d")
n = A("n")

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

class B:
    def __init__(self, txt: str):
        self.q: 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")
d = C("d")
n = A("n")

m.q = a
m.z = a
m.p = n
a.q = n
d.q = n
n.q = a
n.z = a
n.p = m
assert n.p.p.p.q.txt == "a"