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

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

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

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

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

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

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

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

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

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

j.r = n
l.y = j
l.r = j
l.z = i
n.w = l
i.u = n
i.z = j
i.y = j
assert n.w.z.u.txt == "n"