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

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

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

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

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

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

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