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

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

b = A("b")
e = B("e")
k = B("k")
g = A("g")
d = B("d")
c = B("c")
i = A("i")
h = B("h")

b.s = i
e.o = d
k.o = c
g.s = i
d.o = k
c.o = e
i.s = b
h.o = c
assert b.s.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

b = A("b")
e = B("e")
k = B("k")
g = A("g")
d = B("d")
c = B("c")
i = A("i")
h = B("h")

b.s = i
e.o = d
k.o = c
g.s = i
d.o = k
c.o = e
i.s = b
h.o = c
assert b.s.s.s.s.s.s.txt == "b"