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

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

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

class D:
    def __init__(self, txt: str):
        self.q: E = None
        self.txt = txt

class E:
    def __init__(self, txt: str):
        self.q: D = None
        self.x: D = None
        self.txt = txt

b = A("b")
f = B("f")
m = C("m")
d = D("d")
k = E("k")

b.u = k
f.p = m
f.u = d
f.q = k
m.u = f
m.w = d
m.z = b
d.q = k
k.q = d
k.x = d
assert f.p.u.u.q.x.txt == "
class A:
    def __init__(self, txt: str):
        self.u: E = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.q: E = None
        self.txt = txt

class E:
    def __init__(self, txt: str):
        self.q: D = None
        self.x: D = None
        self.txt = txt

b = A("b")
f = B("f")
m = C("m")
d = D("d")
k = E("k")

b.u = k
f.p = m
f.u = d
f.q = k
m.u = f
m.w = d
m.z = b
d.q = k
k.q = d
k.x = d
assert f.p.u.u.q.x.txt == "d"