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

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

j = A("j")
n = B("n")
h = A("h")
i = A("i")
m = A("m")

j.w = h
n.z = m
h.w = j
i.w = j
m.w = i
assert j.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.z: A = None
        self.txt = txt

j = A("j")
n = B("n")
h = A("h")
i = A("i")
m = A("m")

j.w = h
n.z = m
h.w = j
i.w = j
m.w = i
assert j.w.w.w.w.w.txt == "h"