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

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

n = A("n")
i = B("i")
e = A("e")
g = B("g")

n.o = e
i.s = g
e.o = n
g.s = i
assert e.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.s: B = None
        self.txt = txt

n = A("n")
i = B("i")
e = A("e")
g = B("g")

n.o = e
i.s = g
e.o = n
g.s = i
assert e.o.o.o.o.txt == "e"