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

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

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

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

m = A("m")
n = B("n")
l = C("l")
f = D("f")
j = D("j")
g = D("g")

m.t = j
m.w = n
n.r = j
n.z = l
n.x = f
l.s = n
f.q = n
j.q = n
g.q = n
assert f.q.z.s.x.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: D = None
        self.w: B = None
        self.txt = txt

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

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

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

m = A("m")
n = B("n")
l = C("l")
f = D("f")
j = D("j")
g = D("g")

m.t = j
m.w = n
n.r = j
n.z = l
n.x = f
l.s = n
f.q = n
j.q = n
g.q = n
assert f.q.z.s.x.q.txt == "n"