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

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

a = A("a")
n = B("n")
g = B("g")
f = A("f")
b = A("b")
e = A("e")

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

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

a = A("a")
n = B("n")
g = B("g")
f = A("f")
b = A("b")
e = A("e")

a.o = g
a.s = f
n.x = a
g.x = b
f.o = n
f.s = b
b.o = g
b.s = f
e.o = g
e.s = b
assert e.o.x.s.o.x.txt == "a"