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

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

f = A("f")
m = B("m")
j = B("j")
a = A("a")

f.w = a
m.r = f
m.o = f
j.r = a
j.o = a
a.w = f
assert j.r.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: A = None
        self.o: A = None
        self.txt = txt

f = A("f")
m = B("m")
j = B("j")
a = A("a")

f.w = a
m.r = f
m.o = f
j.r = a
j.o = a
a.w = f
assert j.r.w.w.txt == "a"