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

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

c = A("c")
h = B("h")
a = A("a")
i = B("i")
d = A("d")
m = B("m")
g = A("g")
n = B("n")
k = A("k")
l = A("l")

c.w = k
c.p = n
h.w = i
a.w = l
a.p = m
i.w = h
d.w = c
d.p = n
m.w = i
g.w = a
g.p = n
n.w = i
k.w = a
k.p = h
l.w = d
l.p = i
assert l.p.w.w.w.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.p: B = None
        self.txt = txt

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

c = A("c")
h = B("h")
a = A("a")
i = B("i")
d = A("d")
m = B("m")
g = A("g")
n = B("n")
k = A("k")
l = A("l")

c.w = k
c.p = n
h.w = i
a.w = l
a.p = m
i.w = h
d.w = c
d.p = n
m.w = i
g.w = a
g.p = n
n.w = i
k.w = a
k.p = h
l.w = d
l.p = i
assert l.p.w.w.w.w.w.w.w.w.txt == "i"