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

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

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

n.x = c
n.s = i
e.o = c
e.w = g
c.o = f
c.w = f
g.o = e
g.w = f
f.o = e
f.w = c
i.x = c
i.s = n
assert g.o.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.s: A = None
        self.txt = txt

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

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

n.x = c
n.s = i
e.o = c
e.w = g
c.o = f
c.w = f
g.o = e
g.w = f
f.o = e
f.w = c
i.x = c
i.s = n
assert g.o.o.o.o.o.o.txt == "f"