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

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

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

class D:
    def __init__(self, txt: str):
        self.t: B = None
        self.y: A = None
        self.txt = txt

e = A("e")
k = B("k")
i = C("i")
d = D("d")
m = D("m")

e.r = k
e.y = k
k.p = i
i.v = d
i.z = e
i.r = k
d.t = k
d.y = e
m.t = k
m.y = e
assert d.y.r.p.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.y: B = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.t: B = None
        self.y: A = None
        self.txt = txt

e = A("e")
k = B("k")
i = C("i")
d = D("d")
m = D("m")

e.r = k
e.y = k
k.p = i
i.v = d
i.z = e
i.r = k
d.t = k
d.y = e
m.t = k
m.y = e
assert d.y.r.p.z.r.txt == "k"