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

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

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

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

a = A("a")
d = B("d")
b = C("b")
c = D("c")

a.y = d
a.s = b
d.t = a
b.s = a
c.p = a
c.o = a
c.z = a
assert b.s.y.t.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.s: C = None
        self.txt = txt

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

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

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

a = A("a")
d = B("d")
b = C("b")
c = D("c")

a.y = d
a.s = b
d.t = a
b.s = a
c.p = a
c.o = a
c.z = a
assert b.s.y.t.y.txt == "d"