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

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

g = A("g")
l = B("l")
a = B("a")
j = A("j")
k = A("k")
i = B("i")

g.s = k
l.s = a
a.s = l
j.s = k
k.s = j
i.s = a
assert g.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.s: B = None
        self.txt = txt

g = A("g")
l = B("l")
a = B("a")
j = A("j")
k = A("k")
i = B("i")

g.s = k
l.s = a
a.s = l
j.s = k
k.s = j
i.s = a
assert g.s.s.s.s.s.txt == "k"