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

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

a = A("a")
b = B("b")
l = A("l")
j = B("j")
k = A("k")
n = A("n")
g = B("g")
f = B("f")

a.y = l
a.s = l
b.s = g
l.y = k
l.s = a
j.s = f
k.y = l
k.s = n
n.y = l
n.s = a
g.s = j
f.s = g
assert k.y.y.s.y.y.s.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.s: A = None
        self.txt = txt

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

a = A("a")
b = B("b")
l = A("l")
j = B("j")
k = A("k")
n = A("n")
g = B("g")
f = B("f")

a.y = l
a.s = l
b.s = g
l.y = k
l.s = a
j.s = f
k.y = l
k.s = n
n.y = l
n.s = a
g.s = j
f.s = g
assert k.y.y.s.y.y.s.txt == "n"