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

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

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

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

i = A("i")
m = B("m")
e = C("e")
j = D("j")

i.z = m
i.s = e
m.r = j
e.r = j
j.r = m
assert j.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.s: C = None
        self.txt = txt

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

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

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

i = A("i")
m = B("m")
e = C("e")
j = D("j")

i.z = m
i.s = e
m.r = j
e.r = j
j.r = m
assert j.r.r.r.r.txt == "j"