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

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

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

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

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

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

i.w = h
j.r = m
h.w = i
m.r = j
assert i.w.w.w.w.txt == "i"