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

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

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

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

i = A("i")
k = B("k")
a = C("a")
b = D("b")

i.w = b
k.u = b
k.z = b
k.w = i
a.u = k
a.z = k
a.w = i
b.w = a
b.u = a
b.r = i
assert i.w.r.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: D = None
        self.txt = txt

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

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

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

i = A("i")
k = B("k")
a = C("a")
b = D("b")

i.w = b
k.u = b
k.z = b
k.w = i
a.u = k
a.z = k
a.w = i
b.w = a
b.u = a
b.r = i
assert i.w.r.w.r.txt == "i"