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

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

f = A("f")
m = B("m")
b = A("b")
n = B("n")

f.o = b
f.t = b
m.y = n
m.r = b
b.o = f
b.t = f
n.y = m
n.r = f
assert m.y.y.y.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.t: A = None
        self.txt = txt

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

f = A("f")
m = B("m")
b = A("b")
n = B("n")

f.o = b
f.t = b
m.y = n
m.r = b
b.o = f
b.t = f
n.y = m
n.r = f
assert m.y.y.y.r.txt == "f"