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

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

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

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

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

d.s = b
d.w = e
j.s = d
a.w = e
a.q = d
b.w = e
e.w = b
assert b.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.w: D = None
        self.txt = txt

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

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

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

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

d.s = b
d.w = e
j.s = d
a.w = e
a.q = d
b.w = e
e.w = b
assert b.w.w.w.txt == "e"