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

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

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

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

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

n.w = j
n.o = j
d.w = e
m.u = c
m.y = d
m.s = d
j.r = m
e.w = d
c.w = j
c.o = j
assert d.w.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: D = None
        self.o: D = None
        self.txt = txt

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

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

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

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

n.w = j
n.o = j
d.w = e
m.u = c
m.y = d
m.s = d
j.r = m
e.w = d
c.w = j
c.o = j
assert d.w.w.w.w.w.w.txt == "d"