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

class B:
    def __init__(self, txt: str):
        self.y: B = None
        self.w: B = None
        self.txt = txt

h = A("h")
d = B("d")
n = A("n")
c = B("c")
l = B("l")
j = A("j")
e = B("e")
i = A("i")

h.r = c
d.y = c
d.w = l
n.r = l
c.y = d
c.w = e
l.y = e
l.w = c
j.r = e
e.y = l
e.w = c
i.r = e
assert j.r.y.y.y.y.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: B = None
        self.w: B = None
        self.txt = txt

h = A("h")
d = B("d")
n = A("n")
c = B("c")
l = B("l")
j = A("j")
e = B("e")
i = A("i")

h.r = c
d.y = c
d.w = l
n.r = l
c.y = d
c.w = e
l.y = e
l.w = c
j.r = e
e.y = l
e.w = c
i.r = e
assert j.r.y.y.y.y.w.txt == "c"