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

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

m = A("m")
c = B("c")
j = B("j")

m.y = j
c.t = m
c.w = m
j.t = m
j.w = m
assert m.y.t.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

m = A("m")
c = B("c")
j = B("j")

m.y = j
c.t = m
c.w = m
j.t = m
j.w = m
assert m.y.t.y.txt == "j"