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

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

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

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

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

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

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

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

n.z = f
g.z = d
g.q = d
f.p = d
d.z = g
d.q = g
assert n.z.p.q.q.txt == "d"