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

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

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

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

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

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

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