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

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

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

n = A("n")
m = B("m")
d = C("d")
f = C("f")

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

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

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

n = A("n")
m = B("m")
d = C("d")
f = C("f")

n.z = m
n.x = m
n.q = d
m.p = n
m.q = d
d.t = m
f.t = m
assert m.q.t.p.txt == "n"