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

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

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

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

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

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

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