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

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

g = A("g")
b = B("b")
e = B("e")
i = A("i")
m = B("m")

g.o = i
b.y = i
b.x = e
e.y = g
e.x = b
i.o = g
m.y = g
m.x = e
assert m.x.y.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.y: A = None
        self.x: B = None
        self.txt = txt

g = A("g")
b = B("b")
e = B("e")
i = A("i")
m = B("m")

g.o = i
b.y = i
b.x = e
e.y = g
e.x = b
i.o = g
m.y = g
m.x = e
assert m.x.y.o.o.o.txt == "i"