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

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

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

a.z = n
a.s = d
a.v = b
d.p = b
n.p = d
b.z = a
b.s = d
assert d.p.s.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.s: B = None
        self.v: D = None
        self.txt = txt

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

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

a.z = n
a.s = d
a.v = b
d.p = b
n.p = d
b.z = a
b.s = d
assert d.p.s.p.s.txt == "d"