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

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

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

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

c = A("c")
g = B("g")
e = C("e")
n = D("n")
k = B("k")
d = C("d")

c.q = e
g.u = d
e.r = g
e.p = n
n.z = g
k.u = d
d.r = k
d.p = n
assert d.r.u.r.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

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

c = A("c")
g = B("g")
e = C("e")
n = D("n")
k = B("k")
d = C("d")

c.q = e
g.u = d
e.r = g
e.p = n
n.z = g
k.u = d
d.r = k
d.p = n
assert d.r.u.r.u.p.txt == "n"