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

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

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

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

d = A("d")
c = B("c")
n = C("n")
i = D("i")
k = A("k")

d.z = k
c.s = d
c.z = k
n.u = d
i.v = n
i.z = n
i.r = k
k.z = d
assert i.z.u.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

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

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

d = A("d")
c = B("c")
n = C("n")
i = D("i")
k = A("k")

d.z = k
c.s = d
c.z = k
n.u = d
i.v = n
i.z = n
i.r = k
k.z = d
assert i.z.u.z.z.txt == "d"