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

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

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

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

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

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

g.o = n
g.r = m
m.o = g
n.s = m
n.z = m
n.q = m
n.p = b
n.w = d
b.p = g
b.z = g
d.u = b
d.z = b
d.p = n
assert d.p.w.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.r: B = None
        self.txt = txt

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

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

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

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

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

g.o = n
g.r = m
m.o = g
n.s = m
n.z = m
n.q = m
n.p = b
n.w = d
b.p = g
b.z = g
d.u = b
d.z = b
d.p = n
assert d.p.w.z.z.txt == "g"