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

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

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

h.w = i
b.w = i
b.u = h
c.w = h
n.w = i
n.u = i
j.w = h
j.u = i
i.w = h
k.w = i
k.u = c
assert i.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.w: A = None
        self.u: A = None
        self.txt = txt

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

h.w = i
b.w = i
b.u = h
c.w = h
n.w = i
n.u = i
j.w = h
j.u = i
i.w = h
k.w = i
k.u = c
assert i.w.w.w.w.w.txt == "h"