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

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

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

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

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

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

m.t = c
m.s = j
l.w = j
c.w = m
j.t = c
j.s = m
assert c.w.t.w.txt == "m"