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

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

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

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

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

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

h.r = i
b.x = k
b.o = h
f.x = k
f.o = k
m.r = k
k.r = i
i.r = h
assert h.r.r.r.r.r.txt == "i"