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

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

h = A("h")
m = B("m")
g = A("g")

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

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

h = A("h")
m = B("m")
g = A("g")

h.o = m
h.r = g
m.v = g
g.o = m
g.r = h
assert h.r.r.r.txt == "g"