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

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

a = A("a")
j = B("j")
b = A("b")
f = A("f")
d = A("d")
m = A("m")
n = A("n")
k = A("k")
l = B("l")
e = B("e")

a.s = m
j.z = l
b.s = a
f.s = n
d.s = f
m.s = f
n.s = m
k.s = f
l.z = e
e.z = l
assert b.s.s.s.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.z: B = None
        self.txt = txt

a = A("a")
j = B("j")
b = A("b")
f = A("f")
d = A("d")
m = A("m")
n = A("n")
k = A("k")
l = B("l")
e = B("e")

a.s = m
j.z = l
b.s = a
f.s = n
d.s = f
m.s = f
n.s = m
k.s = f
l.z = e
e.z = l
assert b.s.s.s.s.s.s.s.s.s.txt == "f"