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

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

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

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

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

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

i.o = b
m.o = c
m.y = c
b.o = i
f.o = m
f.y = n
n.o = f
n.y = c
c.o = n
c.y = n
assert i.o.o.o.o.txt == "i"