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

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

b = A("b")
i = B("i")
h = A("h")
j = B("j")
n = B("n")
d = A("d")

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

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

b = A("b")
i = B("i")
h = A("h")
j = B("j")
n = B("n")
d = A("d")

b.w = j
b.y = i
i.w = j
h.w = i
h.y = n
j.w = n
n.w = j
d.w = j
d.y = i
assert j.w.w.w.txt == "n"