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

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

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

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

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

d.w = e
d.r = n
e.w = n
n.w = e
n.q = e
m.r = n
m.q = n
m.z = d
m.p = d
f.r = n
f.q = n
f.z = d
f.p = d
assert e.w.w.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.r: C = None
        self.txt = txt

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

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

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

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

d.w = e
d.r = n
e.w = n
n.w = e
n.q = e
m.r = n
m.q = n
m.z = d
m.p = d
f.r = n
f.q = n
f.z = d
f.p = d
assert e.w.w.w.q.txt == "e"