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

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

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

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

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

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

i.t = n
i.w = n
n.x = i
c.t = n
c.w = n
assert c.t.x.t.txt == "n"