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

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

f = A("f")
l = B("l")
m = B("m")
b = A("b")
i = A("i")

f.r = l
f.w = b
l.x = i
l.r = m
m.x = b
m.r = l
b.r = l
b.w = f
i.r = m
i.w = b
assert f.r.r.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.w: A = None
        self.txt = txt

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

f = A("f")
l = B("l")
m = B("m")
b = A("b")
i = A("i")

f.r = l
f.w = b
l.x = i
l.r = m
m.x = b
m.r = l
b.r = l
b.w = f
i.r = m
i.w = b
assert f.r.r.r.x.txt == "i"