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

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

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

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

d = A("d")
l = B("l")
m = C("m")
j = D("j")
e = C("e")
n = C("n")

d.q = j
l.w = j
l.y = j
l.z = d
m.x = e
m.z = e
m.y = n
m.r = l
j.z = d
e.x = m
e.y = n
e.z = n
e.r = l
n.x = m
n.y = m
n.z = e
n.r = l
assert d.q.z.q.z.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

d = A("d")
l = B("l")
m = C("m")
j = D("j")
e = C("e")
n = C("n")

d.q = j
l.w = j
l.y = j
l.z = d
m.x = e
m.z = e
m.y = n
m.r = l
j.z = d
e.x = m
e.y = n
e.z = n
e.r = l
n.x = m
n.y = m
n.z = e
n.r = l
assert d.q.z.q.z.q.z.txt == "d"