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

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

m = A("m")
i = B("i")
f = B("f")
b = B("b")
k = A("k")
e = B("e")
g = B("g")
c = B("c")

m.o = b
i.r = f
f.r = g
b.r = i
k.o = g
e.r = b
g.r = f
c.r = b
assert b.r.r.r.r.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: B = None
        self.txt = txt

m = A("m")
i = B("i")
f = B("f")
b = B("b")
k = A("k")
e = B("e")
g = B("g")
c = B("c")

m.o = b
i.r = f
f.r = g
b.r = i
k.o = g
e.r = b
g.r = f
c.r = b
assert b.r.r.r.r.r.txt == "g"