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

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

class C:
    def __init__(self, txt: str):
        self.w: D = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

h = A("h")
b = B("b")
c = C("c")
i = D("i")
g = D("g")
e = D("e")

h.o = b
b.r = e
b.p = c
b.u = i
c.w = e
i.w = c
g.w = c
e.w = c
assert e.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.w: D = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

h = A("h")
b = B("b")
c = C("c")
i = D("i")
g = D("g")
e = D("e")

h.o = b
b.r = e
b.p = c
b.u = i
c.w = e
i.w = c
g.w = c
e.w = c
assert e.w.w.w.w.txt == "e"