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

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

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

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

f = A("f")
k = B("k")
b = C("b")
c = D("c")

f.x = k
f.p = b
f.w = b
k.z = b
k.x = c
k.s = c
k.r = f
b.u = k
b.z = k
c.p = b
assert b.z.r.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.p: C = None
        self.w: C = None
        self.txt = txt

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

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

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

f = A("f")
k = B("k")
b = C("b")
c = D("c")

f.x = k
f.p = b
f.w = b
k.z = b
k.x = c
k.s = c
k.r = f
b.u = k
b.z = k
c.p = b
assert b.z.r.w.txt == "b"