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

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

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

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

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

d.q = l
d.y = n
i.w = j
i.r = j
i.z = d
j.t = n
n.y = l
l.w = j
l.r = j
l.z = d
assert i.w.t.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.y: D = None
        self.txt = txt

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

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

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

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

d.q = l
d.y = n
i.w = j
i.r = j
i.z = d
j.t = n
n.y = l
l.w = j
l.r = j
l.z = d
assert i.w.t.y.z.txt == "d"