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

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

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

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

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

j.s = b
k.p = j
k.z = j
k.r = f
f.y = b
f.u = b
f.s = k
b.y = f
assert b.y.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.txt = txt

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

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

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

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

j.s = b
k.p = j
k.z = j
k.r = f
f.y = b
f.u = b
f.s = k
b.y = f
assert b.y.s.r.txt == "f"