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

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

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

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

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

e = A("e")
g = B("g")
i = C("i")
b = D("b")
a = E("a")
m = A("m")

e.r = b
g.y = e
g.s = e
g.v = e
g.q = a
i.p = g
i.r = e
i.v = b
b.o = g
b.p = i
b.u = m
a.w = m
m.r = b
assert b.o.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

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

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

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

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

e = A("e")
g = B("g")
i = C("i")
b = D("b")
a = E("a")
m = A("m")

e.r = b
g.y = e
g.s = e
g.v = e
g.q = a
i.p = g
i.r = e
i.v = b
b.o = g
b.p = i
b.u = m
a.w = m
m.r = b
assert b.o.q.w.txt == "m"