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

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

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

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

d = A("d")
h = B("h")
j = C("j")
b = D("b")

d.s = h
h.p = d
h.v = j
j.v = h
b.v = j
b.p = h
b.w = d
assert d.s.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

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

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

d = A("d")
h = B("h")
j = C("j")
b = D("b")

d.s = h
h.p = d
h.v = j
j.v = h
b.v = j
b.p = h
b.w = d
assert d.s.v.v.v.txt == "j"