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

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

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

i.w = a
a.t = i
a.w = i
n.t = i
n.w = i
assert i.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

i.w = a
a.t = i
a.w = i
n.t = i
n.w = i
assert i.w.w.w.txt == "a"