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

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

f = A("f")
a = B("a")
i = B("i")
c = A("c")
m = A("m")
j = A("j")
e = B("e")
n = B("n")
g = B("g")
h = A("h")

f.w = h
a.t = m
i.t = j
c.w = m
m.w = h
j.w = m
e.t = f
n.t = m
g.t = m
h.w = m
assert e.t.w.w.w.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

f = A("f")
a = B("a")
i = B("i")
c = A("c")
m = A("m")
j = A("j")
e = B("e")
n = B("n")
g = B("g")
h = A("h")

f.w = h
a.t = m
i.t = j
c.w = m
m.w = h
j.w = m
e.t = f
n.t = m
g.t = m
h.w = m
assert e.t.w.w.w.w.w.w.w.w.txt == "m"