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

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

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

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

h = A("h")
f = B("f")
l = C("l")
i = D("i")
b = D("b")
j = C("j")

h.s = l
f.y = i
f.v = j
l.w = b
i.z = b
i.v = b
i.s = h
i.p = h
b.z = i
b.v = i
b.s = h
b.p = h
j.w = b
assert i.z.p.s.w.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

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

h = A("h")
f = B("f")
l = C("l")
i = D("i")
b = D("b")
j = C("j")

h.s = l
f.y = i
f.v = j
l.w = b
i.z = b
i.v = b
i.s = h
i.p = h
b.z = i
b.v = i
b.s = h
b.p = h
j.w = b
assert i.z.p.s.w.txt == "b"