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

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

h = A("h")
k = B("k")
c = B("c")
a = B("a")
f = A("f")
m = A("m")
g = B("g")
d = B("d")

h.s = f
k.o = m
c.o = m
a.o = h
f.s = h
m.s = f
g.o = m
d.o = h
assert g.o.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: A = None
        self.txt = txt

h = A("h")
k = B("k")
c = B("c")
a = B("a")
f = A("f")
m = A("m")
g = B("g")
d = B("d")

h.s = f
k.o = m
c.o = m
a.o = h
f.s = h
m.s = f
g.o = m
d.o = h
assert g.o.s.s.s.s.txt == "h"