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

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

f = A("f")
n = B("n")
b = A("b")
c = B("c")
j = B("j")
g = A("g")
e = A("e")

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

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

f = A("f")
n = B("n")
b = A("b")
c = B("c")
j = B("j")
g = A("g")
e = A("e")

f.o = b
f.s = j
n.w = j
b.o = g
b.s = n
c.w = j
j.w = n
g.o = f
g.s = c
e.o = b
e.s = j
assert j.w.w.w.w.txt == "j"