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

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

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

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

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

d = A("d")
h = B("h")
g = C("g")
e = D("e")
c = E("c")

d.p = e
h.u = d
h.p = c
g.w = e
g.x = c
e.p = c
c.o = d
c.x = d
c.y = e
assert e.p.y.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

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

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

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

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

d = A("d")
h = B("h")
g = C("g")
e = D("e")
c = E("c")

d.p = e
h.u = d
h.p = c
g.w = e
g.x = c
e.p = c
c.o = d
c.x = d
c.y = e
assert e.p.y.p.txt == "c"