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

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

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

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

l = A("l")
n = B("n")
a = C("a")
m = D("m")
j = C("j")

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

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

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

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

l = A("l")
n = B("n")
a = C("a")
m = D("m")
j = C("j")

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