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

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

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

m.s = b
m.r = b
h.v = b
h.o = m
b.s = m
b.r = m
f.s = b
f.r = b
assert f.r.r.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.r: A = None
        self.txt = txt

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

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

m.s = b
m.r = b
h.v = b
h.o = m
b.s = m
b.r = m
f.s = b
f.r = b
assert f.r.r.s.txt == "b"