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

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

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

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

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

k = A("k")
c = B("c")
a = C("a")
f = D("f")
d = E("d")

k.u = c
k.w = d
c.o = k
c.v = a
a.z = f
f.p = a
f.q = a
f.r = a
d.w = k
d.r = k
d.y = k
assert d.r.w.y.w.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.w: E = None
        self.txt = txt

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

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

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

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

k = A("k")
c = B("c")
a = C("a")
f = D("f")
d = E("d")

k.u = c
k.w = d
c.o = k
c.v = a
a.z = f
f.p = a
f.q = a
f.r = a
d.w = k
d.r = k
d.y = k
assert d.r.w.y.w.txt == "d"