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

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

f = A("f")
i = B("i")
j = B("j")
g = B("g")
k = B("k")

f.o = g
i.r = f
j.r = f
g.r = f
k.r = f
assert i.r.o.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

f = A("f")
i = B("i")
j = B("j")
g = B("g")
k = B("k")

f.o = g
i.r = f
j.r = f
g.r = f
k.r = f
assert i.r.o.r.txt == "f"