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

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

n = A("n")
i = B("i")
a = A("a")
f = B("f")
m = B("m")
g = A("g")

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

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

n = A("n")
i = B("i")
a = A("a")
f = B("f")
m = B("m")
g = A("g")

n.o = m
i.y = f
a.o = f
f.y = i
m.y = f
g.o = f
assert a.o.y.y.txt == "f"