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

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

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

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

n = A("n")
f = B("f")
i = C("i")
d = D("d")

n.s = i
f.w = n
i.x = n
i.w = f
i.s = d
d.s = i
assert i.x.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

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

n = A("n")
f = B("f")
i = C("i")
d = D("d")

n.s = i
f.w = n
i.x = n
i.w = f
i.s = d
d.s = i
assert i.x.s.s.txt == "d"