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

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

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

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

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

n.p = b
i.v = n
i.x = b
d.w = n
b.y = n
b.s = i
assert i.x.s.x.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

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

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

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

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

n.p = b
i.v = n
i.x = b
d.w = n
b.y = n
b.s = i
assert i.x.s.x.s.txt == "i"