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

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

f = A("f")
h = B("h")
l = B("l")
k = B("k")
a = A("a")
j = A("j")
i = B("i")
d = B("d")
e = B("e")

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

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

f = A("f")
h = B("h")
l = B("l")
k = B("k")
a = A("a")
j = A("j")
i = B("i")
d = B("d")
e = B("e")

f.p = a
h.w = i
l.w = k
k.w = i
a.p = j
j.p = f
i.w = d
d.w = e
e.w = h
assert d.w.w.w.w.w.w.w.w.txt == "d"