class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.r: D = None
        self.z: C = 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.t: D = None
        self.u: A = None
        self.o: A = None
        self.r: D = None
        self.txt = txt

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

d = A("d")
g = B("g")
h = C("h")
k = D("k")

d.u = k
d.r = k
d.z = h
g.z = h
h.t = k
h.r = k
h.u = d
h.o = d
k.r = h
assert g.z.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.r: D = None
        self.z: C = 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.t: D = None
        self.u: A = None
        self.o: A = None
        self.r: D = None
        self.txt = txt

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

d = A("d")
g = B("g")
h = C("h")
k = D("k")

d.u = k
d.r = k
d.z = h
g.z = h
h.t = k
h.r = k
h.u = d
h.o = d
k.r = h
assert g.z.r.r.r.txt == "k"