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

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

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

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

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

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

c.u = m
f.r = c
a.u = d
a.s = m
a.q = m
m.x = f
i.q = f
i.w = f
d.q = f
d.w = f
assert d.w.r.u.x.r.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.txt = txt

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

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

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

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

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

c.u = m
f.r = c
a.u = d
a.s = m
a.q = m
m.x = f
i.q = f
i.w = f
d.q = f
d.w = f
assert d.w.r.u.x.r.u.txt == "m"