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

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

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

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

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

l = A("l")
c = B("c")
a = C("a")
h = D("h")
e = E("e")
f = C("f")
m = C("m")

l.p = e
l.w = h
c.u = l
a.p = l
a.r = f
h.r = c
h.t = c
e.q = h
f.p = l
f.r = a
m.p = l
m.r = f
assert h.r.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: E = None
        self.w: D = None
        self.txt = txt

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

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

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

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

l = A("l")
c = B("c")
a = C("a")
h = D("h")
e = E("e")
f = C("f")
m = C("m")

l.p = e
l.w = h
c.u = l
a.p = l
a.r = f
h.r = c
h.t = c
e.q = h
f.p = l
f.r = a
m.p = l
m.r = f
assert h.r.u.p.txt == "e"