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

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

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

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

n = A("n")
i = B("i")
k = C("k")
j = D("j")
m = A("m")
b = C("b")

n.w = m
i.p = n
k.o = j
k.s = m
k.q = b
j.o = k
j.z = n
j.p = i
j.w = i
m.w = n
b.o = j
b.s = n
b.q = k
assert b.s.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

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

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

n = A("n")
i = B("i")
k = C("k")
j = D("j")
m = A("m")
b = C("b")

n.w = m
i.p = n
k.o = j
k.s = m
k.q = b
j.o = k
j.z = n
j.p = i
j.w = i
m.w = n
b.o = j
b.s = n
b.q = k
assert b.s.w.w.w.w.w.txt == "m"