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

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

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

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

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

i.z = f
a.r = i
a.y = i
j.s = i
j.p = l
j.u = a
l.r = m
m.r = l
f.r = i
f.y = i
assert l.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

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

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

i.z = f
a.r = i
a.y = i
j.s = i
j.p = l
j.u = a
l.r = m
m.r = l
f.r = i
f.y = i
assert l.r.r.r.r.txt == "l"