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

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

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

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

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

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

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

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

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