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

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

j = A("j")
m = B("m")
h = A("h")
k = A("k")
l = B("l")
f = B("f")
a = A("a")
b = B("b")

j.s = f
j.o = k
m.s = j
h.s = f
h.o = j
k.s = l
k.o = j
l.s = a
f.s = a
a.s = f
a.o = j
b.s = h
assert j.s.s.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.o: A = None
        self.txt = txt

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

j = A("j")
m = B("m")
h = A("h")
k = A("k")
l = B("l")
f = B("f")
a = A("a")
b = B("b")

j.s = f
j.o = k
m.s = j
h.s = f
h.o = j
k.s = l
k.o = j
l.s = a
f.s = a
a.s = f
a.o = j
b.s = h
assert j.s.s.s.s.s.s.s.txt == "f"