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

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

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

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

i = A("i")
k = B("k")
j = C("j")
a = D("a")
f = D("f")
d = A("d")

i.z = k
i.r = j
i.u = d
k.z = j
j.y = i
a.y = j
f.y = j
d.z = k
d.r = j
d.u = i
assert d.z.z.y.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.r: C = None
        self.u: A = None
        self.txt = txt

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

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

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

i = A("i")
k = B("k")
j = C("j")
a = D("a")
f = D("f")
d = A("d")

i.z = k
i.r = j
i.u = d
k.z = j
j.y = i
a.y = j
f.y = j
d.z = k
d.r = j
d.u = i
assert d.z.z.y.txt == "i"