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

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

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

g.w = l
n.z = l
n.s = l
i.z = l
i.s = g
l.w = g
assert l.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

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

g.w = l
n.z = l
n.s = l
i.z = l
i.s = g
l.w = g
assert l.w.w.w.txt == "g"