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

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

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

i.w = h
c.t = j
c.p = h
h.t = c
h.p = d
l.w = c
j.t = d
j.p = h
e.w = h
f.w = h
d.t = j
d.p = j
m.w = j
assert f.w.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

i.w = h
c.t = j
c.p = h
h.t = c
h.p = d
l.w = c
j.t = d
j.p = h
e.w = h
f.w = h
d.t = j
d.p = j
m.w = j
assert f.w.p.p.p.txt == "h"