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

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

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

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

j = A("j")
l = B("l")
b = C("b")
i = D("i")

j.s = b
l.r = i
l.y = i
l.t = j
b.y = j
i.z = b
i.w = b
i.r = l
assert b.y.s.y.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

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

j = A("j")
l = B("l")
b = C("b")
i = D("i")

j.s = b
l.r = i
l.y = i
l.t = j
b.y = j
i.z = b
i.w = b
i.r = l
assert b.y.s.y.txt == "j"