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

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

i = A("i")
h = B("h")
a = B("a")
n = A("n")

i.w = n
h.p = a
h.w = n
a.p = h
a.w = n
n.w = i
assert n.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.p: B = None
        self.w: A = None
        self.txt = txt

i = A("i")
h = B("h")
a = B("a")
n = A("n")

i.w = n
h.p = a
h.w = n
a.p = h
a.w = n
n.w = i
assert n.w.w.w.w.txt == "n"