class A:
    def __init__(self, txt: str):
        self.q: B = 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.p: B = None
        self.txt = txt

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

n = A("n")
b = B("b")
k = C("k")
f = D("f")
d = A("d")
j = B("j")
e = C("e")
a = D("a")

n.q = j
b.w = j
k.p = j
f.w = b
d.q = b
j.w = b
e.p = b
a.w = j
assert j.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = 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.p: B = None
        self.txt = txt

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

n = A("n")
b = B("b")
k = C("k")
f = D("f")
d = A("d")
j = B("j")
e = C("e")
a = D("a")

n.q = j
b.w = j
k.p = j
f.w = b
d.q = b
j.w = b
e.p = b
a.w = j
assert j.w.w.w.txt == "b"