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

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

a = A("a")
g = B("g")
l = A("l")
n = A("n")

a.s = n
g.z = l
l.s = a
n.s = l
assert a.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: A = None
        self.txt = txt

a = A("a")
g = B("g")
l = A("l")
n = A("n")

a.s = n
g.z = l
l.s = a
n.s = l
assert a.s.s.s.s.txt == "n"