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

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

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

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

b = A("b")
i = B("i")
k = C("k")
f = D("f")
d = B("d")

b.y = f
b.s = f
b.p = f
i.q = b
i.z = k
k.z = d
f.w = b
f.q = i
d.q = b
d.z = k
assert d.z.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.s: D = None
        self.p: D = None
        self.txt = txt

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

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

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

b = A("b")
i = B("i")
k = C("k")
f = D("f")
d = B("d")

b.y = f
b.s = f
b.p = f
i.q = b
i.z = k
k.z = d
f.w = b
f.q = i
d.q = b
d.z = k
assert d.z.z.q.txt == "b"