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

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

j = A("j")
n = B("n")
b = B("b")
e = B("e")
c = B("c")
i = B("i")
h = A("h")

j.w = h
n.s = i
b.s = e
e.s = c
c.s = i
i.s = e
h.w = j
assert b.s.s.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

j = A("j")
n = B("n")
b = B("b")
e = B("e")
c = B("c")
i = B("i")
h = A("h")

j.w = h
n.s = i
b.s = e
e.s = c
c.s = i
i.s = e
h.w = j
assert b.s.s.s.s.s.s.s.txt == "e"