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

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

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

n = A("n")
l = B("l")
e = C("e")
i = B("i")
b = A("b")
h = C("h")
d = A("d")
f = C("f")

n.p = d
l.o = e
l.r = f
l.w = i
e.o = l
i.o = h
i.r = h
i.w = l
b.p = n
h.o = i
d.p = n
f.o = l
assert h.o.r.o.w.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

n = A("n")
l = B("l")
e = C("e")
i = B("i")
b = A("b")
h = C("h")
d = A("d")
f = C("f")

n.p = d
l.o = e
l.r = f
l.w = i
e.o = l
i.o = h
i.r = h
i.w = l
b.p = n
h.o = i
d.p = n
f.o = l
assert h.o.r.o.w.txt == "l"