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

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

class C:
    def __init__(self, txt: str):
        self.s: B = None
        self.y: E = None
        self.txt = txt

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

class E:
    def __init__(self, txt: str):
        self.y: C = None
        self.v: C = None
        self.q: B = None
        self.t: C = None
        self.txt = txt

n = A("n")
b = B("b")
a = C("a")
d = D("d")
m = E("m")

n.r = b
b.x = d
b.u = n
a.s = b
a.y = m
d.w = a
d.r = a
d.p = b
d.y = n
m.y = a
m.v = a
m.t = a
m.q = b
assert m.q.u.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.s: B = None
        self.y: E = None
        self.txt = txt

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

class E:
    def __init__(self, txt: str):
        self.y: C = None
        self.v: C = None
        self.q: B = None
        self.t: C = None
        self.txt = txt

n = A("n")
b = B("b")
a = C("a")
d = D("d")
m = E("m")

n.r = b
b.x = d
b.u = n
a.s = b
a.y = m
d.w = a
d.r = a
d.p = b
d.y = n
m.y = a
m.v = a
m.t = a
m.q = b
assert m.q.u.r.txt == "b"