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

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

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

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

a = A("a")
j = B("j")
e = C("e")
f = D("f")

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

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

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

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

a = A("a")
j = B("j")
e = C("e")
f = D("f")

a.s = f
j.o = a
e.u = a
e.r = f
e.s = f
f.y = j
f.z = j
f.p = j
assert j.o.s.y.txt == "j"