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

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

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

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

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

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

g.o = i
b.s = g
b.r = i
b.w = k
b.p = m
d.s = i
m.o = b
i.x = g
i.y = g
i.q = b
i.p = b
i.s = d
k.s = i
assert m.o.p.o.w.s.txt == "
class A:
    def __init__(self, txt: str):
        self.o: E = None
        self.txt = txt

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

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

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

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

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

g.o = i
b.s = g
b.r = i
b.w = k
b.p = m
d.s = i
m.o = b
i.x = g
i.y = g
i.q = b
i.p = b
i.s = d
k.s = i
assert m.o.p.o.w.s.txt == "i"