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

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

h = A("h")
d = B("d")
k = B("k")
i = B("i")
c = A("c")
a = A("a")
f = A("f")
n = B("n")
b = A("b")

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

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

h = A("h")
d = B("d")
k = B("k")
i = B("i")
c = A("c")
a = A("a")
f = A("f")
n = B("n")
b = A("b")

h.w = c
h.y = n
d.p = i
k.p = n
i.p = d
c.w = h
c.y = i
a.w = c
a.y = n
f.w = a
f.y = i
n.p = i
b.w = c
b.y = k
assert i.p.p.p.p.p.p.p.p.p.txt == "d"