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

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

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

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

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

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

j.o = i
j.w = m
i.y = j
i.r = j
m.y = j
m.r = j
assert j.w.r.w.txt == "m"